TYPO3 CMS  TYPO3_6-2
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 = array();
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  $this->uninitializedViewHelper = $viewHelper;
56  $this->viewHelpersByContext = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Persistence\\ObjectStorage');
57  $this->arguments = $arguments;
58  $this->viewHelperClassName = get_class($this->uninitializedViewHelper);
59  }
60 
67  public function getUninitializedViewHelper() {
69  }
70 
76  public function getViewHelperClassName() {
78  }
79 
86  public function getArguments() {
87  return $this->arguments;
88  }
89 
103  public function evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext) {
104  if ($this->viewHelpersByContext->contains($renderingContext)) {
105  $viewHelper = $this->viewHelpersByContext[$renderingContext];
106  $viewHelper->resetState();
107  } else {
108  $viewHelper = clone $this->uninitializedViewHelper;
109  $this->viewHelpersByContext->attach($renderingContext, $viewHelper);
110  }
111 
112  $evaluatedArguments = array();
113  if (count($viewHelper->prepareArguments())) {
114  foreach ($viewHelper->prepareArguments() as $argumentName => $argumentDefinition) {
115  if (isset($this->arguments[$argumentName])) {
116  $argumentValue = $this->arguments[$argumentName];
117  $evaluatedArguments[$argumentName] = $argumentValue->evaluate($renderingContext);
118  } else {
119  $evaluatedArguments[$argumentName] = $argumentDefinition->getDefaultValue();
120  }
121  }
122  }
123 
124  $viewHelper->setArguments($evaluatedArguments);
125  $viewHelper->setViewHelperNode($this);
126  $viewHelper->setRenderingContext($renderingContext);
127 
128  if ($viewHelper instanceof \TYPO3\CMS\Fluid\Core\ViewHelper\Facets\ChildNodeAccessInterface) {
129  $viewHelper->setChildNodes($this->childNodes);
130  }
131 
132  $output = $viewHelper->initializeArgumentsAndRender();
133 
134  return $output;
135  }
136 
142  public function __sleep() {
143  return array('viewHelperClassName', 'arguments', 'childNodes');
144  }
145 }
evaluate(\TYPO3\CMS\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
__construct(\TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper $viewHelper, array $arguments)