/** * Render the form. * * @param string $action Target action * @param array $arguments Arguments * @param string $controller Target controller * @param string $extensionName Target Extension Name (without "tx_" prefix and no underscores). If NULL the current extension name is used * @param string $pluginName Target plugin. If empty, the current plugin name is used * @param integer $pageUid Target page uid * @param mixed $object Object to use for the form. Use in conjunction with the "property" attribute on the sub tags * @param integer $pageType Target page type * @param boolean $noCache set this to disable caching for the target page. You should not need this. * @param boolean $noCacheHash set this to supress the cHash query parameter created by TypoLink. You should not need this. * @param string $section The anchor to be added to the action URI (only active if $actionUri is not set) * @param string $format The requested format (e.g. ".html") of the target page (only active if $actionUri is not set) * @param array $additionalParams additional action URI query parameters that won't be prefixed like $arguments (overrule $arguments) (only active if $actionUri is not set) * @param boolean $absolute If set, an absolute action URI is rendered (only active if $actionUri is not set) * @param boolean $addQueryString If set, the current query parameters will be kept in the action URI (only active if $actionUri is not set) * @param array $argumentsToBeExcludedFromQueryString arguments to be removed from the action URI. Only active if $addQueryString = TRUE and $actionUri is not set * @param string $fieldNamePrefix Prefix that will be added to all field names within this form. If not set the prefix will be tx_yourExtension_plugin * @param string $actionUri can be used to overwrite the "action" attribute of the form tag * @param string $objectName name of the object that is bound to this form. If this argument is not specified, the name attribute of this form is used to determine the FormObjectName * @param string $resultTarget target where the results will be loaded * @param string $loaders target where the loader will be shown * @return string rendered form */ public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $object = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $fieldNamePrefix = NULL, $actionUri = NULL, $objectName = NULL, $resultTarget = NULL, $loaders = NULL) { $this->renderHijaxDataAttributes($action, $arguments, $controller, $extensionName, $pluginName); $this->hijaxEventDispatcher->setIsHijaxElement(true); if ($resultTarget) { $this->tag->addAttribute('data-hijax-result-target', $resultTarget); } else { /* @var $listener \EssentialDots\ExtbaseHijax\Event\Listener */ $listener = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager')->get('EssentialDots\\ExtbaseHijax\\MVC\\Dispatcher')->getCurrentListener(); $this->tag->addAttribute('data-hijax-result-target', "jQuery(this).parents('.hijax-element[data-hijax-listener-id=\"" . $listener->getId() . "\"]')"); $this->tag->addAttribute('data-hijax-result-wrap', 'false'); } if ($loaders) { $this->tag->addAttribute('data-hijax-loaders', $loaders); } parent::render($action, $arguments, $controller, $extensionName, $pluginName, $pageUid, $object, $pageType, $noCache, $noCacheHash, $section, $format, $additionalParams, $absolute, $addQueryString, $argumentsToBeExcludedFromQueryString, $fieldNamePrefix, $actionUri, $objectName); $this->tag->setContent('<div class="hijax-content">' . $this->tag->getContent() . '</div><div class="hijax-loading"></div>'); return $this->tag->render(); }
/** * Returns JS callback for the given action * * @param null $action * @param array $arguments * @param null $controller * @param null $extensionName * @param null $pluginName * @param string $format * @param string $section * @return string */ public function getAjaxFunction($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $format = '', $section = 'footer') { // current element needs to have additional logic... $this->hijaxEventDispatcher->setIsHijaxElement(true); $request = $this->mvcDispatcher->getCurrentRequest(); 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(); } } $settings = array('extension' => $extensionName, 'plugin' => $pluginName, 'controller' => $controller, 'format' => $format ? $format : 'html', 'action' => $action, 'arguments' => $arguments, 'settingsHash' => $this->mvcDispatcher->getCurrentListener() ? $this->mvcDispatcher->getCurrentListener()->getId() : '', 'namespace' => $extensionName && $pluginName ? $this->extensionService->getPluginNamespace($extensionName, $pluginName) : ''); $functionName = 'extbaseHijax_' . md5(serialize($settings)); $content = "; {$functionName}=function(settings, pendingElement, loaders) {"; foreach ($settings as $k => $v) { $content .= "if (typeof settings.{$k} == 'undefined') settings.{$k}=" . json_encode($v) . ";"; } $content .= "return jQuery.hijax(settings, pendingElement, loaders);};"; if ($this->isCached()) { if ($section == 'footer') { $this->pageRenderer->addJsFooterInlineCode(md5($content), $content, FALSE, TRUE); } else { $this->pageRenderer->addJsInlineCode(md5($content), $content, FALSE, TRUE); } } else { // additionalFooterData not possible in USER_INT $GLOBALS['TSFE']->additionalHeaderData[md5($content)] = \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS($content); } return $functionName; }
/** * 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(); } }