/** * @param string $action * @param array $arguments * @param string $controller * @param string $extensionName * @param string $pluginName * @param string $format * @param int $pageUid * @param boolean $cachedAjaxIfPossible TRUE if the URI should be cached (with respect to non-cacheable actions) * @param boolean $forceContext TRUE if the controller/action/... should be passed * @param boolean $noAjax * * @return string */ public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $format = '', $pageUid = NULL, $cachedAjaxIfPossible = TRUE, $forceContext = TRUE, $noAjax = FALSE) { $request = $this->mvcDispatcher->getCurrentRequest(); if ($forceContext) { $requestArguments = $this->controllerContext->getRequest()->getArguments(); $requestArguments = array_merge($requestArguments, $this->hijaxEventDispatcher->getContextArguments()); $requestArguments = array_merge($requestArguments, $arguments); $arguments = $requestArguments; } if ($noAjax) { return parent::render($action, $arguments, $controller, $extensionName, $pluginName, $pageUid); } else { /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */ $listener = $this->mvcDispatcher->getCurrentListener(); if ($request) { if ($action === NULL) { $action = $request->getControllerActionName(); } if ($controller === NULL) { $controller = $request->getControllerName(); } if ($extensionName === NULL) { $extensionName = $request->getControllerExtensionName(); } if ($pluginName === NULL && TYPO3_MODE === 'FE') { $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action); } if ($pluginName === NULL) { $pluginName = $request->getPluginName(); } $cachedAjaxIfPossible = $cachedAjaxIfPossible ? $this->configurationManager->getContentObject()->getUserObjectType() != ContentObjectRenderer::OBJECTTYPE_USER_INT : false; if ($cachedAjaxIfPossible) { /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */ $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator'); $chash = $cacheHash->calculateCacheHash(array('encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 'action' => $action, 'controller' => $controller, 'extension' => $extensionName, 'plugin' => $pluginName, 'arguments' => $this->array_map_recursive('strval', $arguments), 'settingsHash' => $listener->getId())); } } $additionalArguments = array(); $this->hA('r[0][arguments]', $arguments, $additionalArguments); $language = intval($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->sys_language_content : 0); $additionalParams = "&r[0][extension]={$extensionName}&r[0][plugin]={$pluginName}&r[0][controller]={$controller}&r[0][action]={$action}&r[0][format]={$format}&r[0][settingsHash]={$listener->getId()}&eID=extbase_hijax_dispatcher&L={$language}"; if ($additionalArguments) { $additionalParams .= '&' . implode('&', $additionalArguments); } if ($chash) { $additionalParams .= '&r[0][chash]=' . $chash; } /* @var $cObj \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer */ $cObj = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\ContentObject\\ContentObjectRenderer'); $uri = $cObj->typoLink('', array('returnLast' => 'url', 'additionalParams' => $additionalParams, 'parameter' => $pageUid ? $pageUid : ($GLOBALS['TSFE'] ? $GLOBALS['TSFE']->id : 0))); $this->tag->addAttribute('href', $uri); $this->tag->setContent($this->renderChildren()); $this->tag->forceClosingTag(TRUE); return $this->tag->render(); } }
/** * Renders hijax-related data attributes * * @param null $action * @param array $arguments * @param array $contextArguments * @param bool $ajax * @param bool $cachedAjaxIfPossible * @param bool $forceContext * @return string */ protected function getWidgetUri($action = NULL, array $arguments = array(), array $contextArguments = array(), $ajax = TRUE, $cachedAjaxIfPossible = TRUE, $forceContext = FALSE) { $this->hijaxEventDispatcher->setIsHijaxElement(true); $request = $this->controllerContext->getRequest(); /* @var $widgetContext \EssentialDots\ExtbaseHijax\Core\Widget\WidgetContext */ $widgetContext = $request->getWidgetContext(); $tagAttributes = array(); if ($ajax) { $tagAttributes['data-hijax-element-type'] = 'link'; $this->tag->addAttribute('class', trim($this->arguments['class'] . ' hijax-element')); } if ($action === NULL) { $action = $widgetContext->getParentControllerContext()->getRequest()->getControllerActionName(); } if ($ajax) { $tagAttributes['data-hijax-action'] = $action; } $controller = $widgetContext->getParentControllerContext()->getRequest()->getControllerName(); if ($ajax) { $tagAttributes['data-hijax-controller'] = $controller; } $extensionName = $widgetContext->getParentControllerContext()->getRequest()->getControllerExtensionName(); if ($ajax) { $tagAttributes['data-hijax-extension'] = $extensionName; } if (TYPO3_MODE === 'FE') { $pluginName = $this->extensionService->getPluginNameByAction($extensionName, $controller, $action); } if (!$pluginName) { $pluginName = $request->getPluginName(); } if (!$pluginName) { $pluginName = $widgetContext->getParentPluginName(); } if ($ajax) { $tagAttributes['data-hijax-plugin'] = $pluginName; } $pluginNamespace = $this->extensionService->getPluginNamespace($extensionName, $pluginName); if ($ajax) { $tagAttributes['data-hijax-namespace'] = $pluginNamespace; } $requestArguments = $widgetContext->getParentControllerContext()->getRequest()->getArguments(); $requestArguments = array_merge($requestArguments, $this->hijaxEventDispatcher->getContextArguments()); $requestArguments = array_merge($requestArguments, $contextArguments); $requestArguments[$widgetContext->getWidgetIdentifier()] = $arguments && is_array($arguments) ? $arguments : array(); if (version_compare(TYPO3_version, '6.1.0', '>=')) { $variableContainer = $widgetContext->getViewHelperChildNodeRenderingContext()->getViewHelperVariableContainer(); if ($variableContainer->exists('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames')) { $formFieldNames = $variableContainer->get('TYPO3\\CMS\\Fluid\\ViewHelpers\\FormViewHelper', 'formFieldNames'); $mvcPropertyMappingConfigurationService = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\MvcPropertyMappingConfigurationService'); /* @var $mvcPropertyMappingConfigurationService \TYPO3\CMS\Extbase\Mvc\Controller\MvcPropertyMappingConfigurationService */ $requestHash = $mvcPropertyMappingConfigurationService->generateTrustedPropertiesToken($formFieldNames, $pluginNamespace); $requestArguments['__trustedProperties'] = $requestHash; } } if ($ajax) { $tagAttributes['data-hijax-arguments'] = serialize($requestArguments); } /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */ $listener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('EssentialDots\\ExtbaseHijax\\MVC\\Dispatcher')->getCurrentListener(); if ($ajax) { $tagAttributes['data-hijax-settings'] = $listener->getId(); } $cachedAjaxIfPossible = $cachedAjaxIfPossible ? $this->configurationManager->getContentObject()->getUserObjectType() != ContentObjectRenderer::OBJECTTYPE_USER_INT : false; if ($cachedAjaxIfPossible) { /* @var $cacheHash \TYPO3\CMS\Frontend\Page\CacheHashCalculator */ $cacheHash = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\CacheHashCalculator'); $tagAttributes['data-hijax-chash'] = $cacheHash->calculateCacheHash(array('encryptionKey' => $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'], 'action' => $tagAttributes['data-hijax-action'], 'controller' => $tagAttributes['data-hijax-controller'], 'extension' => $tagAttributes['data-hijax-extension'], 'plugin' => $tagAttributes['data-hijax-plugin'], 'arguments' => $tagAttributes['data-hijax-arguments'], 'settingsHash' => $tagAttributes['data-hijax-settings'])); } foreach ($tagAttributes as $tagAttribute => $attributeValue) { $this->tag->addAttribute($tagAttribute, $attributeValue); } $uriBuilder = $this->controllerContext->getUriBuilder(); $argumentPrefix = $this->controllerContext->getRequest()->getArgumentPrefix(); if ($this->hasArgument('format') && $this->arguments['format'] !== '') { $requestArguments['format'] = $this->arguments['format']; } $uriBuilder->reset()->setArguments(array($pluginNamespace => $requestArguments))->setSection($this->arguments['section'])->setAddQueryString(TRUE)->setArgumentsToBeExcludedFromQueryString(array($argumentPrefix, 'cHash'))->setFormat($this->arguments['format']); if ($forceContext) { return $uriBuilder->uriFor($action, $arguments, $controller, $extensionName, $pluginName); } else { return $uriBuilder->build(); } }