[FEATURE] EXT:form - integrate new form framework
[Packages/TYPO3.CMS.git] / typo3 / sysext / form / Classes / ViewHelpers / Be / RenderContentElementPreviewViewHelper.php
1 <?php
2 declare(strict_types=1);
3 namespace TYPO3\CMS\Form\ViewHelpers\Be;
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 use TYPO3\CMS\Backend\Utility\BackendUtility;
19 use TYPO3\CMS\Backend\View\PageLayoutView;
20 use TYPO3\CMS\Core\Utility\GeneralUtility;
21 use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
22 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
23 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
24
25 /**
26 * Used by the form editor.
27 * Render a content element preview like the page module
28 *
29 * Scope: backend
30 * @internal
31 */
32 class RenderContentElementPreviewViewHelper extends AbstractViewHelper
33 {
34 use CompileWithRenderStatic;
35
36 /**
37 * As this ViewHelper renders HTML, the output must not be escaped.
38 *
39 * @var bool
40 */
41 protected $escapeOutput = false;
42
43 /**
44 * Initialize arguments.
45 *
46 * @return void
47 * @internal
48 */
49 public function initializeArguments()
50 {
51 parent::initializeArguments();
52 $this->registerArgument('contentElementUid', 'int', 'The uid of a content element');
53 }
54
55 /**
56 * @param array $arguments
57 * @param callable|\Closure $renderChildrenClosure
58 * @param RenderingContextInterface $renderingContext
59 * @return string
60 * @internal
61 */
62 public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
63 {
64 $content = '';
65 $contentElementUid = $arguments['contentElementUid'];
66 $contentRecord = BackendUtility::getRecord('tt_content', $contentElementUid);
67 if (!empty($contentRecord)) {
68 $pageLayoutView = GeneralUtility::makeInstance(PageLayoutView::class);
69 $content = $pageLayoutView->tt_content_drawItem($contentRecord);
70 }
71 return $content;
72 }
73 }