Example #1
0
 /**
  * Adds a ViewHelper node using the Format\HtmlspecialcharsViewHelper to the given node.
  * If "escapingInterceptorEnabled" in the ViewHelper is FALSE, will disable itself inside the ViewHelpers body.
  *
  * @param \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $node
  * @param int $interceptorPosition One of the INTERCEPT_* constants for the current interception point
  * @param \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState the current parsing state. Not needed in this interceptor.
  * @return \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface
  */
 public function process(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\NodeInterface $node, $interceptorPosition, \TYPO3\CMS\Fluid\Core\Parser\ParsingState $parsingState)
 {
     if ($interceptorPosition === \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_OPENING_VIEWHELPER) {
         if (!$node->getUninitializedViewHelper()->isEscapingInterceptorEnabled()) {
             $this->interceptorEnabled = false;
             $this->viewHelperNodesWhichDisableTheInterceptor[] = $node;
         }
     } elseif ($interceptorPosition === \TYPO3\CMS\Fluid\Core\Parser\InterceptorInterface::INTERCEPT_CLOSING_VIEWHELPER) {
         if (end($this->viewHelperNodesWhichDisableTheInterceptor) === $node) {
             array_pop($this->viewHelperNodesWhichDisableTheInterceptor);
             if (count($this->viewHelperNodesWhichDisableTheInterceptor) === 0) {
                 $this->interceptorEnabled = true;
             }
         }
     } elseif ($this->interceptorEnabled && $node instanceof \TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ObjectAccessorNode) {
         $escapeViewHelper = $this->objectManager->get(\TYPO3\CMS\Fluid\ViewHelpers\Format\HtmlspecialcharsViewHelper::class);
         $node = $this->objectManager->get(\TYPO3\CMS\Fluid\Core\Parser\SyntaxTree\ViewHelperNode::class, $escapeViewHelper, array('value' => $node));
     }
     return $node;
 }
 /**
  * @param array $arguments
  * @param array $variables
  * @param NodeInterface $childNode
  * @param string $extensionName
  * @param string $pluginName
  * @return AbstractViewHelper
  */
 protected function buildViewHelperInstance($arguments = array(), $variables = array(), $childNode = NULL, $extensionName = NULL, $pluginName = NULL)
 {
     $instance = $this->createInstance();
     /** @var TemplateVariableContainer $container */
     $container = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TemplateVariableContainer');
     /** @var ViewHelperVariableContainer $viewHelperContainer */
     $viewHelperContainer = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\ViewHelperVariableContainer');
     if (0 < count($variables)) {
         ObjectAccess::setProperty($container, 'variables', $variables, TRUE);
     }
     $node = new ViewHelperNode($instance, $arguments);
     /** @var UriBuilder $uriBuilder */
     $uriBuilder = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Routing\\UriBuilder');
     /** @var Request $request */
     $request = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Request');
     if (NULL !== $extensionName) {
         $request->setControllerExtensionName($extensionName);
     }
     if (NULL !== $pluginName) {
         $request->setPluginName($pluginName);
     }
     /** @var Response $response */
     $response = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Web\\Response');
     /** @var ControllerContext $controllerContext */
     $controllerContext = $this->objectManager->get('TYPO3\\CMS\\Extbase\\Mvc\\Controller\\ControllerContext');
     $controllerContext->setRequest($request);
     $controllerContext->setResponse($response);
     $controllerContext->setUriBuilder($uriBuilder);
     /** @var RenderingContext $renderingContext */
     $renderingContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Rendering\\RenderingContext');
     $renderingContext->setControllerContext($controllerContext);
     ObjectAccess::setProperty($renderingContext, 'viewHelperVariableContainer', $viewHelperContainer, TRUE);
     ObjectAccess::setProperty($renderingContext, 'templateVariableContainer', $container, TRUE);
     $instance->setArguments($arguments);
     $instance->setRenderingContext($renderingContext);
     $instance->setRenderChildrenClosure(function () use($childNode, $renderingContext) {
         return NULL === $childNode ? NULL : $childNode->evaluate($renderingContext);
     });
     if (TRUE === $instance instanceof AbstractWidgetViewHelper) {
         /** @var WidgetContext $widgetContext */
         $widgetContext = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\Widget\\WidgetContext');
         ObjectAccess::setProperty($instance, 'widgetContext', $widgetContext, TRUE);
     }
     if (NULL !== $childNode) {
         $node->addChildNode($childNode);
         if ($instance instanceof ChildNodeAccessInterface) {
             $instance->setChildNodes(array($childNode));
         }
     }
     $instance->setViewHelperNode($node);
     return $instance;
 }