TYPO3 CMS  TYPO3_7-6
ViewHelperNode.php
Go to the documentation of this file.
1 <?php
3 
4 /* *
5  * This script is backported from the TYPO3 Flow package "TYPO3.Fluid". *
6  * *
7  * It is free software; you can redistribute it and/or modify it under *
8  * the terms of the GNU Lesser General Public License, either version 3 *
9  * of the License, or (at your option) any later version. *
10  * *
11  * The TYPO3 project - inspiring people to share! *
12  * */
13 
18 {
25 
31  protected $arguments = [];
32 
38  protected $uninitializedViewHelper = null;
39 
46  protected $viewHelpersByContext = null;
47 
54  public function __construct(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper, array $arguments)
55  {
56  $this->uninitializedViewHelper = $viewHelper;
57  $this->viewHelpersByContext = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Persistence\ObjectStorage::class);
58  $this->arguments = $arguments;
59  $this->viewHelperClassName = get_class($this->uninitializedViewHelper);
60  }
61 
68  public function getUninitializedViewHelper()
69  {
71  }
72 
78  public function getViewHelperClassName()
79  {
81  }
82 
89  public function getArguments()
90  {
91  return $this->arguments;
92  }
93 
107  public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
108  {
109  if ($this->viewHelpersByContext->contains($renderingContext)) {
110  $viewHelper = $this->viewHelpersByContext[$renderingContext];
111  $viewHelper->resetState();
112  } else {
113  $viewHelper = clone $this->uninitializedViewHelper;
114  $this->viewHelpersByContext->attach($renderingContext, $viewHelper);
115  }
116 
117  $evaluatedArguments = [];
118  if (count($viewHelper->prepareArguments())) {
119  foreach ($viewHelper->prepareArguments() as $argumentName => $argumentDefinition) {
120  if (isset($this->arguments[$argumentName])) {
121  $argumentValue = $this->arguments[$argumentName];
122  $evaluatedArguments[$argumentName] = $argumentValue->evaluate($renderingContext);
123  } else {
124  $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue();
125  }
126  }
127  }
128 
129  $viewHelper->setArguments($evaluatedArguments);
130  $viewHelper->setViewHelperNode($this);
131  $viewHelper->setRenderingContext($renderingContext);
132 
133  if ($viewHelper instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface) {
134  $viewHelper->setChildNodes($this->childNodes);
135  }
136 
137  $output = $viewHelper->initializeArgumentsAndRender();
138 
139  return $output;
140  }
141 
147  public function __sleep()
148  {
149  return ['viewHelperClassName', 'arguments', 'childNodes'];
150  }
151 }
evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
__construct(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper, array $arguments)