‪TYPO3CMS  ‪main
RenderContentElementPreviewViewHelper.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 
19 
20 use TYPO3\CMS\Backend\Utility\BackendUtility;
26 use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
27 use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
28 use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
29 
37 final class ‪RenderContentElementPreviewViewHelper extends AbstractViewHelper
38 {
39  use CompileWithRenderStatic;
40 
46  protected ‪$escapeOutput = false;
47 
48  public function ‪initializeArguments(): void
49  {
50  $this->registerArgument('contentElementUid', 'int', 'The uid of a content element');
51  }
52 
53  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
54  {
55  $content = '';
56  $contentElementUid = $arguments['contentElementUid'];
57  $contentRecord = BackendUtility::getRecord('tt_content', $contentElementUid);
58  if (!empty($contentRecord)) {
59  $backendLayout = GeneralUtility::makeInstance(BackendLayout::class, 'dummy', 'dummy', []);
60  $pageRow = BackendUtility::getRecord('pages', $contentRecord['pid']);
61  $pageLayoutContext = GeneralUtility::makeInstance(PageLayoutContext::class, $pageRow, $backendLayout);
62  $gridColumn = GeneralUtility::makeInstance(GridColumn::class, $pageLayoutContext, []);
63  $columnItem = GeneralUtility::makeInstance(GridColumnItem::class, $pageLayoutContext, $gridColumn, $contentRecord);
64  return $columnItem->getPreview();
65  }
66  return $content;
67  }
68 }
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper\$escapeOutput
‪bool $escapeOutput
Definition: RenderContentElementPreviewViewHelper.php:44
‪TYPO3\CMS\Form\ViewHelpers\Be
Definition: MaximumFileSizeViewHelper.php:18
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper\initializeArguments
‪initializeArguments()
Definition: RenderContentElementPreviewViewHelper.php:46
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper
Definition: RenderContentElementPreviewViewHelper.php:38
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper\renderStatic
‪static renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderContentElementPreviewViewHelper.php:51
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:44
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:42
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:27
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:45