1414 *
1515 */
1616
17- use Helhum \TyposcriptRendering \Configuration \RecordRenderingConfigurationBuilder ;
18- use Helhum \TyposcriptRendering \Renderer \RenderingContext ;
17+ use Helhum \TyposcriptRendering \Uri \TyposcriptRenderingUri ;
18+ use Helhum \TyposcriptRendering \Uri \ViewHelperContext ;
19+ use TYPO3Fluid \Fluid \Core \ViewHelper \AbstractTagBasedViewHelper ;
1920
20- class LinkViewHelper extends \ TYPO3 \ CMS \ Fluid \ Core \ ViewHelper \ AbstractTagBasedViewHelper
21+ class LinkViewHelper extends AbstractTagBasedViewHelper
2122{
2223 /**
2324 * @var string
2425 */
2526 protected $ tagName = 'a ' ;
2627
27- /**
28- * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManager
29- * @inject
30- */
31- protected $ configurationManager ;
32-
3328 /**
3429 * Initialize arguments
3530 *
@@ -39,133 +34,50 @@ class LinkViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedVi
3934 */
4035 public function initializeArguments ()
4136 {
37+ parent ::initializeArguments ();
4238 $ this ->registerUniversalTagAttributes ();
4339 $ this ->registerTagAttribute ('name ' , 'string ' , 'Specifies the name of an anchor ' );
4440 $ this ->registerTagAttribute ('rel ' , 'string ' , 'Specifies the relationship between the current document and the linked document ' );
4541 $ this ->registerTagAttribute ('rev ' , 'string ' , 'Specifies the relationship between the linked document and the current document ' );
4642 $ this ->registerTagAttribute ('target ' , 'string ' , 'Specifies where to open the linked document ' );
43+ // @deprecated
44+ $ this ->registerArgument ('useCacheHash ' , 'bool ' , 'Deprecated: True whether the cache hash should be appended to the URL ' , false , null );
4745 $ this ->registerArgument ('addQueryStringMethod ' , 'string ' , 'Method to be used for query string ' );
48- }
46+ $ this ->registerArgument ('action ' , 'string ' , 'Target action ' );
47+ $ this ->registerArgument ('arguments ' , 'array ' , 'Arguments ' , false , []);
48+ $ this ->registerArgument ('section ' , 'string ' , 'The anchor to be added to the URI ' , false , '' );
49+ $ this ->registerArgument ('format ' , 'string ' , 'The requested format, e.g. ".html ' , false , '' );
50+ $ this ->registerArgument ('ajax ' , 'bool ' , 'TRUE if the URI should be to an AJAX widget, FALSE otherwise. ' , false , true );
4951
50- /**
51- * Render the Uri.
52- *
53- * @param string $pluginName
54- * @param string $extensionName
55- * @param string $action Target action
56- * @param array $arguments Arguments
57- * @param string $section The anchor to be added to the URI
58- * @param string $format The requested format, e.g. ".html
59- * @param bool $ajax true if the URI should be to an Ajax widget, false otherwise.
60- * @param string $contextRecord The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), 'currentPage' record of current page
61- *
62- * @throws \Helhum\TyposcriptRendering\Configuration\ConfigurationBuildingException
63- * @return string The rendered link
64- *
65- */
66- public function render ($ pluginName , $ extensionName , $ action = null , array $ arguments = [], $ section = '' , $ format = '' , $ ajax = true , $ contextRecord = 'current ' )
67- {
68- if ($ ajax === true ) {
69- $ uri = $ this ->getAjaxUri ();
70- } else {
71- $ uri = $ this ->getWidgetUri ();
72- }
73- $ this ->tag ->addAttribute ('href ' , $ uri );
74- $ this ->tag ->setContent ($ this ->renderChildren ());
75- return $ this ->tag ->render ();
52+ $ this ->registerArgument ('extensionName ' , 'string ' , 'Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used ' );
53+ $ this ->registerArgument ('pluginName ' , 'string ' , 'Target plugin. If empty, the current plugin name is used ' );
54+ $ this ->registerArgument ('contextRecord ' , 'string ' , 'The record that the rendering should depend upon. e.g. current (default: record is fetched from current Extbase plugin), tt_content:12 (tt_content record with uid 12), pages:15 (pages record with uid 15), \'currentPage \' record of current page ' , false , 'current ' );
55+ $ this ->registerArgument ('argumentsToBeExcludedFromQueryString ' , 'array ' , 'arguments to be removed from the URI. Only active if $addQueryString = TRUE ' , false , []);
7656 }
7757
7858 /**
79- * Gets the URI for an Ajax Request.
80- *
81- * @throws \Helhum\TyposcriptRendering\Configuration\ConfigurationBuildingException
82- * @return string the Ajax URI
59+ * Render the link.
8360 *
61+ * @return string The rendered link
8462 */
85- protected function getAjaxUri ()
86- {
87- $ pluginName = $ this ->arguments ['pluginName ' ];
88- $ extensionName = $ this ->arguments ['extensionName ' ];
89- $ contextRecord = $ this ->arguments ['contextRecord ' ];
90- $ arguments = $ this ->hasArgument ('arguments ' ) ? $ this ->arguments ['arguments ' ] : [];
91- if ($ contextRecord === 'current ' ) {
92- if (
93- $ pluginName !== $ this ->controllerContext ->getRequest ()->getPluginName ()
94- || $ extensionName !== $ this ->controllerContext ->getRequest ()->getControllerExtensionName ()
95- ) {
96- $ contextRecord = 'currentPage ' ;
97- } else {
98- $ contextRecord = $ this ->configurationManager ->getContentObject ()->currentRecord ;
99- }
100- }
101- $ renderingConfiguration = $ this ->buildTypoScriptRenderingConfiguration ($ extensionName , $ pluginName , $ contextRecord );
102- $ additionalParams ['tx_typoscriptrendering ' ]['context ' ] = json_encode ($ renderingConfiguration );
103-
104- $ uriBuilder = $ this ->controllerContext ->getUriBuilder ();
105- $ argumentPrefix = $ this ->controllerContext ->getRequest ()->getArgumentPrefix ();
106-
107- $ uriBuilder ->reset ()
108- ->setArguments (array_merge ([$ argumentPrefix => $ arguments ], $ additionalParams ))
109- ->setSection ($ this ->arguments ['section ' ])
110- ->setAddQueryString (true )
111- ->setArgumentsToBeExcludedFromQueryString ([$ argumentPrefix , 'cHash ' ])
112- ->setFormat ($ this ->arguments ['format ' ])
113- ->setUseCacheHash (true );
114-
115- // TYPO3 6.0 compatibility check:
116- if (method_exists ($ uriBuilder , 'setAddQueryStringMethod ' )) {
117- $ uriBuilder ->setAddQueryStringMethod ($ this ->arguments ['addQueryStringMethod ' ]);
118- }
119-
120- return $ uriBuilder ->build ();
121- }
122-
123- /**
124- * Gets the URI for a non-Ajax Request.
125- *
126- * @return string the Widget URI
127- */
128- protected function getWidgetUri ()
63+ public function render ()
12964 {
130- $ uriBuilder = $ this ->controllerContext ->getUriBuilder ();
131- $ argumentPrefix = $ this ->controllerContext ->getRequest ()->getArgumentPrefix ();
132- $ arguments = $ this ->hasArgument ('arguments ' ) ? $ this ->arguments ['arguments ' ] : [];
133- if ($ this ->hasArgument ('action ' )) {
134- $ arguments ['action ' ] = $ this ->arguments ['action ' ];
135- }
136- if ($ this ->hasArgument ('format ' ) && $ this ->arguments ['format ' ] !== '' ) {
137- $ arguments ['format ' ] = $ this ->arguments ['format ' ];
138- }
139- if ($ this ->hasArgument ('addQueryStringMethod ' ) && $ this ->arguments ['addQueryStringMethod ' ] !== '' ) {
140- $ arguments ['addQueryStringMethod ' ] = $ this ->arguments ['addQueryStringMethod ' ];
141- }
142- $ uriBuilder ->reset ()
143- ->setArguments ([$ argumentPrefix => $ arguments ])
144- ->setSection ($ this ->arguments ['section ' ])
145- ->setAddQueryString (true )
146- ->setArgumentsToBeExcludedFromQueryString ([$ argumentPrefix , 'cHash ' ])
147- ->setFormat ($ this ->arguments ['format ' ]);
65+ $ arguments = $ this ->arguments ;
14866
149- // TYPO3 6.0 compatibility check:
150- if ( method_exists ( $ uriBuilder , ' setAddQueryStringMethod ' )) {
151- $ uriBuilder -> setAddQueryStringMethod ( $ this -> arguments [ ' addQueryStringMethod ' ] );
67+ if ( $ arguments [ ' ajax ' ] !== true ) {
68+ // @deprecated
69+ trigger_error ( ' Setting the argument "ajax" to false is deprecated. Use the TYPO3 widget view helper instead for such use case. ' , E_USER_DEPRECATED );
15270 }
71+ $ uri = (new TyposcriptRenderingUri ())->withWidgetContext (
72+ new ViewHelperContext (
73+ $ this ->renderingContext ,
74+ $ arguments
75+ )
76+ );
15377
154- return $ uriBuilder -> build ( );
155- }
78+ $ this -> tag -> addAttribute ( ' href ' , ( string ) $ uri );
79+ $ this -> tag -> setContent ( $ this -> renderChildren ());
15680
157- /**
158- * @param string $extensionName
159- * @param string $pluginName
160- * @param string $contextRecord
161- *
162- * @throws \Helhum\TyposcriptRendering\Configuration\ConfigurationBuildingException
163- * @return string[]
164- *
165- */
166- public function buildTypoScriptRenderingConfiguration ($ extensionName , $ pluginName , $ contextRecord )
167- {
168- $ configurationBuilder = new RecordRenderingConfigurationBuilder (new RenderingContext ($ GLOBALS ['TSFE ' ]));
169- return $ configurationBuilder ->configurationFor ($ extensionName , $ pluginName , $ contextRecord );
81+ return $ this ->tag ->render ();
17082 }
17183}
0 commit comments