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