‪TYPO3CMS  9.5
RenderRenderableViewHelper.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It originated from the Neos.Form package (www.neos.io)
9  *
10  * It is free software; you can redistribute it and/or modify it under
11  * the terms of the GNU General Public License, either version 2
12  * of the License, or any later version.
13  *
14  * For the full copyright and license information, please read the
15  * LICENSE.txt file that was distributed with this source code.
16  *
17  * The TYPO3 project - inspiring people to share!
18  */
19 
24 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
25 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
26 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
27 
36 class ‪RenderRenderableViewHelper extends AbstractViewHelper
37 {
38  use CompileWithRenderStatic;
39 
43  protected ‪$escapeOutput = false;
44 
50  public function ‪initializeArguments()
51  {
52  $this->registerArgument('renderable', RootRenderableInterface::class, 'A RenderableInterface instance', true);
53  }
54 
62  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
63  {
64 
66  $formRuntime = $renderingContext
67  ->getViewHelperVariableContainer()
68  ->get(self::class, 'formRuntime');
69 
70  $renderable = $arguments['renderable'];
71 
72  foreach (‪$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/form']['beforeRendering'] ?? [] as $className) {
73  $hookObj = GeneralUtility::makeInstance($className);
74  if (method_exists($hookObj, 'beforeRendering')) {
75  $hookObj->beforeRendering(
76  $formRuntime,
77  $renderable
78  );
79  }
80  }
81 
82  $content = '';
83 
84  if ($renderable instanceof ‪FormRuntime || $renderable instanceof ‪RenderableInterface && $renderable->‪isEnabled()) {
85  $content = $renderChildrenClosure();
86  }
87 
88  // Wrap every renderable with a span with a identifier path data attribute if previewMode is active
89  if (!empty($content)) {
90  $renderingOptions = $formRuntime->getRenderingOptions();
91  if (isset($renderingOptions['previewMode']) && $renderingOptions['previewMode'] === true) {
92  $path = $renderable->getIdentifier();
93  if ($renderable instanceof ‪RenderableInterface) {
94  while ($renderable = $renderable->getParentRenderable()) {
95  $path = $renderable->getIdentifier() . '/' . $path;
96  }
97  }
98  $content = '<span data-element-identifier-path="' . $path . '">' . $content . '</span>';
99  }
100  }
101  return $content;
102  }
103 }
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormRuntime.php:97
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderRenderableViewHelper.php:41
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface
Definition: RenderableInterface.php:28
‪TYPO3\CMS\Form\Domain\Model\Renderable\RootRenderableInterface
Definition: RootRenderableInterface.php:27
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderRenderableViewHelper.php:48
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper
Definition: RenderRenderableViewHelper.php:37
‪TYPO3\CMS\Form\ViewHelpers\RenderRenderableViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderRenderableViewHelper.php:60
‪TYPO3\CMS\Form\ViewHelpers
‪TYPO3\CMS\Form\Domain\Runtime\FormRuntime
Definition: FormSession.php:3
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Form\Domain\Model\Renderable\RenderableInterface\isEnabled
‪bool isEnabled()