/**
  * Assigns multiple values to the JSON output.
  * However, only the key "value" is accepted.
  *
  * @param array $values Keys and values - only a value with key "value" is considered
  * @return \TYPO3\Fluid\View\AbstractTemplateView the instance of this view to allow chaining
  * @api
  */
 public function assignMultiple(array $values)
 {
     $templateVariableContainer = $this->baseRenderingContext->getTemplateVariableContainer();
     foreach ($values as $key => $value) {
         if ($templateVariableContainer->exists($key)) {
             $templateVariableContainer->remove($key);
         }
         $templateVariableContainer->add($key, $value);
     }
     return $this;
 }
Exemplo n.º 2
0
 /**
  * @param array $arguments
  * @param Closure $renderChildrenClosure
  * @param \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return string
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
     if ($arguments['each'] === NULL) {
         return '';
     }
     if (is_object($arguments['each']) && !$arguments['each'] instanceof \Traversable) {
         throw new \TYPO3\Fluid\Core\ViewHelper\Exception('ForViewHelper only supports arrays and objects implementing Traversable interface', 1248728393);
     }
     if ($arguments['reverse'] === TRUE) {
         // array_reverse only supports arrays
         if (is_object($arguments['each'])) {
             $arguments['each'] = iterator_to_array($arguments['each']);
         }
         $arguments['each'] = array_reverse($arguments['each']);
     }
     $iterationData = array('index' => 0, 'cycle' => 1, 'total' => count($arguments['each']));
     $output = '';
     foreach ($arguments['each'] as $keyValue => $singleElement) {
         $templateVariableContainer->add($arguments['as'], $singleElement);
         if ($arguments['key'] !== '') {
             $templateVariableContainer->add($arguments['key'], $keyValue);
         }
         if ($arguments['iteration'] !== NULL) {
             $iterationData['isFirst'] = $iterationData['cycle'] === 1;
             $iterationData['isLast'] = $iterationData['cycle'] === $iterationData['total'];
             $iterationData['isEven'] = $iterationData['cycle'] % 2 === 0;
             $iterationData['isOdd'] = !$iterationData['isEven'];
             $templateVariableContainer->add($arguments['iteration'], $iterationData);
             $iterationData['index']++;
             $iterationData['cycle']++;
         }
         $output .= $renderChildrenClosure();
         $templateVariableContainer->remove($arguments['as']);
         if ($arguments['key'] !== '') {
             $templateVariableContainer->remove($arguments['key']);
         }
         if ($arguments['iteration'] !== NULL) {
             $templateVariableContainer->remove($arguments['iteration']);
         }
     }
     return $output;
 }
 /**
  * @param array $arguments
  * @param \Closure $renderChildrenClosure
  * @param RenderingContextInterface $renderingContext
  * @return string
  * @throws ViewHelper\Exception
  */
 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
 {
     $templateVariableContainer = $renderingContext->getTemplateVariableContainer();
     if ($arguments['each'] === NULL) {
         return '';
     }
     if (!is_array($arguments['each'])) {
         throw new ViewHelper\Exception('DataSheetViewHelper only supports arrays and objects', 1248728393);
     }
     $iterationData = array('index' => 0, 'cycle' => 1, 'total' => count($arguments['each']));
     $output = '';
     foreach ($arguments['each'] as $keyValue => $singleElement) {
         $templateVariableContainer->add($arguments['as'], $singleElement);
         if ($arguments['key'] !== '') {
             $templateVariableContainer->add($arguments['key'], $keyValue);
         }
         if ($arguments['iteration'] !== NULL) {
             $iterationData['isFirst'] = $iterationData['cycle'] === 1;
             $iterationData['isLast'] = $iterationData['cycle'] === $iterationData['total'];
             $iterationData['isEven'] = $iterationData['cycle'] % 2 === 0;
             $iterationData['isOdd'] = !$iterationData['isEven'];
             $templateVariableContainer->add($arguments['iteration'], $iterationData);
             $iterationData['index']++;
             $iterationData['cycle']++;
         }
         $output .= $renderChildrenClosure();
         $templateVariableContainer->remove($arguments['as']);
         if ($arguments['key'] !== '') {
             $templateVariableContainer->remove($arguments['key']);
         }
         if ($arguments['iteration'] !== NULL) {
             $templateVariableContainer->remove($arguments['iteration']);
         }
     }
     return $output;
 }
 /**
  * @param RenderingContextInterface $renderingContext
  * @return void
  */
 public function setRenderingContext(RenderingContextInterface $renderingContext)
 {
     $this->renderingContext = $renderingContext;
     $this->templateVariableContainer = $renderingContext->getTemplateVariableContainer();
     if ($renderingContext->getControllerContext() !== NULL) {
         $this->controllerContext = $renderingContext->getControllerContext();
     }
     $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
 }
 /**
  * @test
  */
 public function templateVariableContainerCanBeReadCorrectly()
 {
     $templateVariableContainer = $this->getMock(\TYPO3\Fluid\Core\ViewHelper\TemplateVariableContainer::class);
     $this->renderingContext->injectTemplateVariableContainer($templateVariableContainer);
     $this->assertSame($this->renderingContext->getTemplateVariableContainer(), $templateVariableContainer, 'Template Variable Container could not be read out again.');
 }
 /**
  * @param \TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext
  * @return void
  */
 public function setRenderingContext(\TYPO3\Fluid\Core\Rendering\RenderingContextInterface $renderingContext)
 {
     $this->renderingContext = $renderingContext;
     $this->templateVariableContainer = $renderingContext->getTemplateVariableContainer();
     $this->viewHelperVariableContainer = $renderingContext->getViewHelperVariableContainer();
 }