‪TYPO3CMS  11.5
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 class ‪RenderContentElementPreviewViewHelper extends AbstractViewHelper
38 {
39  use CompileWithRenderStatic;
40 
46  protected ‪$escapeOutput = false;
47 
53  public function ‪initializeArguments()
54  {
55  $this->registerArgument('contentElementUid', 'int', 'The uid of a content element');
56  }
57 
65  public static function ‪renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
66  {
67  $content = '';
68  $contentElementUid = $arguments['contentElementUid'];
69  $contentRecord = BackendUtility::getRecord('tt_content', $contentElementUid);
70  if (!empty($contentRecord)) {
71  $backendLayout = GeneralUtility::makeInstance(BackendLayout::class, 'dummy', 'dummy', []);
72  $pageRow = BackendUtility::getRecord('pages', $contentRecord['pid']);
73  $pageLayoutContext = GeneralUtility::makeInstance(PageLayoutContext::class, $pageRow, $backendLayout);
74  $gridColumn = GeneralUtility::makeInstance(GridColumn::class, $pageLayoutContext, []);
75  $columnItem = GeneralUtility::makeInstance(GridColumnItem::class, $pageLayoutContext, $gridColumn, $contentRecord);
76  return $columnItem->getPreview();
77  }
78  return $content;
79  }
80 }
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper\renderStatic
‪static string renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
Definition: RenderContentElementPreviewViewHelper.php:63
‪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:51
‪TYPO3\CMS\Form\ViewHelpers\Be\RenderContentElementPreviewViewHelper
Definition: RenderContentElementPreviewViewHelper.php:38
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn
Definition: GridColumn.php:45
‪TYPO3\CMS\Backend\View\PageLayoutContext
Definition: PageLayoutContext.php:43
‪TYPO3\CMS\Backend\View\BackendLayout\BackendLayout
Definition: BackendLayout.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem
Definition: GridColumnItem.php:44