Commit 795102dd authored by Georg Ringer's avatar Georg Ringer Committed by Benni Mack
Browse files

[TASK] Use PreviewRenderer instead of PageLayoutView hooks

As the PageLayoutView is marked as deprecated all usages must be
changed. This patch migrates the hooks from PageLayoutView into
PreviewRenderer.

Resolves: #92926
Releases: master

Change-Id: Ieed06e08c3a3896ad574a3d54d89716c8e8ed808
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/66692


Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Georg Ringer's avatarGeorg Ringer <georg.ringer@gmail.com>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent d711596b
......@@ -17,8 +17,8 @@ declare(strict_types=1);
namespace TYPO3\CMS\Form\Hooks;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Core\Error\Exception;
use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Messaging\AbstractMessage;
......@@ -38,98 +38,79 @@ use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface;
* Contains a preview rendering for the page module of CType="form_formframework"
* @internal
*/
class FormPagePreviewRenderer implements PageLayoutViewDrawItemHookInterface
class FormPagePreviewRenderer extends StandardContentPreviewRenderer
{
/**
* Localisation prefix
*/
const L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
private const L10N_PREFIX = 'LLL:EXT:form/Resources/Private/Language/Database.xlf:';
/**
* Preprocesses the preview rendering of the content element "form_formframework".
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'form_formframework') {
$contentType = $parentObject->CType_labels[$row['CType']];
$itemContent .= $parentObject->linkEditContent('<strong>' . htmlspecialchars($contentType) . '</strong>', $row) . '<br />';
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$row = $item->getRecord();
$itemContent = $this->linkEditContent('<strong>' . htmlspecialchars($item->getContext()->getContentTypeLabels()['form_formframework']) . '</strong>', $row) . '<br />';
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
->convertFlexFormContentToArray($row['pi_flexform']);
$flexFormData = GeneralUtility::makeInstance(FlexFormService::class)
->convertFlexFormContentToArray($row['pi_flexform']);
$persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
if (!empty($persistenceIdentifier)) {
try {
$formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
$persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier'];
if (!empty($persistenceIdentifier)) {
try {
$formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class);
try {
if (
StringUtility::endsWith($persistenceIdentifier, FormPersistenceManager::FORM_DEFINITION_FILE_EXTENSION)
|| strpos($persistenceIdentifier, 'EXT:') === 0
) {
$formDefinition = $formPersistenceManager->load($persistenceIdentifier);
$formLabel = $formDefinition['label'];
} else {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
$persistenceIdentifier
);
}
} catch (ParseErrorException $e) {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
$persistenceIdentifier
);
} catch (PersistenceManagerException $e) {
try {
if (
StringUtility::endsWith($persistenceIdentifier, FormPersistenceManager::FORM_DEFINITION_FILE_EXTENSION)
|| strpos($persistenceIdentifier, 'EXT:') === 0
) {
$formDefinition = $formPersistenceManager->load($persistenceIdentifier);
$formLabel = $formDefinition['label'];
} else {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
$persistenceIdentifier
);
} catch (Exception $e) {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
$persistenceIdentifier
);
}
} catch (NoSuchFileException $e) {
$this->addInvalidFrameworkConfigurationFlashMessage($e);
} catch (ParseErrorException $e) {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidPersistenceIdentifier'),
$persistenceIdentifier
);
} catch (ParseErrorException $e) {
$this->addInvalidFrameworkConfigurationFlashMessage($e);
} catch (PersistenceManagerException $e) {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.inaccessiblePersistenceIdentifier'),
$persistenceIdentifier
);
} catch (Exception $e) {
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
$persistenceIdentifier
);
} catch (\Exception $e) {
// Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
$this->addInvalidFrameworkConfigurationFlashMessage($e);
$formLabel = $e->getMessage();
}
} else {
$formLabel = $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
} catch (NoSuchFileException $e) {
$this->addInvalidFrameworkConfigurationFlashMessage($e);
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.notExistingdPersistenceIdentifier'),
$persistenceIdentifier
);
} catch (ParseErrorException $e) {
$this->addInvalidFrameworkConfigurationFlashMessage($e);
$formLabel = sprintf(
$this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.invalidFrameworkConfiguration'),
$persistenceIdentifier
);
} catch (\Exception $e) {
// Top level catch - FAL throws top level exceptions on missing files, eg. in getFileInfoByIdentifier() of LocalDriver
$this->addInvalidFrameworkConfigurationFlashMessage($e);
$formLabel = $e->getMessage();
}
} else {
$formLabel = $this->getLanguageService()->sL(self::L10N_PREFIX . 'tt_content.preview.noPersistenceIdentifier');
}
$itemContent .= $parentObject->linkEditContent(
$parentObject->renderText($formLabel),
$row
) . '<br />';
$itemContent .= $this->linkEditContent(
htmlspecialchars($formLabel),
$row
) . '<br />';
$drawItem = false;
}
return $itemContent;
}
/**
......
......@@ -18,7 +18,10 @@ declare(strict_types=1);
namespace TYPO3\CMS\Form\ViewHelpers\Be;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\BackendLayout\BackendLayout;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumn;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
use TYPO3\CMS\Backend\View\PageLayoutContext;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
......@@ -65,8 +68,12 @@ class RenderContentElementPreviewViewHelper extends AbstractViewHelper
$contentElementUid = $arguments['contentElementUid'];
$contentRecord = BackendUtility::getRecord('tt_content', $contentElementUid);
if (!empty($contentRecord)) {
$pageLayoutView = GeneralUtility::makeInstance(PageLayoutView::class);
$content = $pageLayoutView->tt_content_drawItem($contentRecord);
$backendLayout = GeneralUtility::makeInstance(BackendLayout::class, 'dummy', 'dummy', []);
$pageRow = BackendUtility::getRecord('pages', $contentRecord['pid']);
$pageLayoutContext = GeneralUtility::makeInstance(PageLayoutContext::class, $pageRow, $backendLayout);
$gridColumn = GeneralUtility::makeInstance(GridColumn::class, $pageLayoutContext, []);
$columnItem = GeneralUtility::makeInstance(GridColumnItem::class, $pageLayoutContext, $gridColumn, $contentRecord);
return $columnItem->getPreview();
}
return $content;
}
......
......@@ -12,6 +12,7 @@ call_user_func(function () {
$GLOBALS['TCA']['tt_content']['ctrl']['typeicon_classes']['form_formframework'] = 'content-form';
$GLOBALS['TCA']['tt_content']['types']['form_formframework']['previewRenderer'] = \TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer::class;
$GLOBALS['TCA']['tt_content']['types']['form_formframework']['showitem'] = '
--div--;LLL:EXT:core/Resources/Private/Language/Form/locallang_tabs.xlf:general,
--palette--;;general,
......
......@@ -31,10 +31,6 @@ call_user_func(function () {
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['GLOBAL']['softRefParser']['formPersistenceIdentifier'] =
\TYPO3\CMS\Form\Hooks\SoftReferenceParserHook::class;
// Register for hook to show preview of tt_content element of CType="form_formframework" in page module
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem']['form_formframework'] =
\TYPO3\CMS\Form\Hooks\FormPagePreviewRenderer::class;
// Add new content element wizard entry
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addPageTSConfig(
"@import 'EXT:form/Configuration/TsConfig/Page/Mod/Wizards/NewContentElement.tsconfig'"
......
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Hooks\PageLayoutView;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
/**
* Contains a preview rendering for the page module of CType="image"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class ImagePreviewRenderer implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of the content element "image".
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'image') {
if ($row['image']) {
$itemContent .= $parentObject->linkEditContent($parentObject->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row);
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'image', $row);
if (!empty($fileReferences)) {
$linkedContent = '';
foreach ($fileReferences as $fileReference) {
$description = $fileReference->getDescription();
if ($description !== null && $description !== '') {
$linkedContent .= htmlspecialchars($description) . '<br />';
}
}
$itemContent .= $parentObject->linkEditContent($linkedContent, $row);
unset($linkedContent);
}
}
$drawItem = false;
}
}
}
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Hooks\PageLayoutView;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
/**
* Contains a preview rendering for the page module of CType="textmedia"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class TextmediaPreviewRenderer implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of a content element of type "textmedia"
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionality
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'textmedia') {
if ($row['bodytext']) {
$itemContent .= $parentObject->linkEditContent($parentObject->renderText($row['bodytext']), $row) . '<br />';
}
if ($row['assets']) {
$itemContent .= $parentObject->linkEditContent($parentObject->getThumbCodeUnlinked($row, 'tt_content', 'assets'), $row) . '<br />';
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'assets', $row);
if (!empty($fileReferences)) {
$linkedContent = '';
foreach ($fileReferences as $fileReference) {
$description = $fileReference->getDescription();
if ($description !== null && $description !== '') {
$linkedContent .= htmlspecialchars($description) . '<br />';
}
}
$itemContent .= $parentObject->linkEditContent($linkedContent, $row);
unset($linkedContent);
}
}
$drawItem = false;
}
}
}
<?php
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Hooks\PageLayoutView;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
/**
* Contains a preview rendering for the page module of CType="textpic"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class TextpicPreviewRenderer implements PageLayoutViewDrawItemHookInterface
{
/**
* Preprocesses the preview rendering of the content element "textpic".
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'textpic') {
if ($row['bodytext']) {
$itemContent .= $parentObject->linkEditContent($parentObject->renderText($row['bodytext']), $row) . '<br />';
}
if ($row['image']) {
$itemContent .= $parentObject->linkEditContent($parentObject->getThumbCodeUnlinked($row, 'tt_content', 'image'), $row);
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'image', $row);
if (!empty($fileReferences)) {
$linkedContent = '';
foreach ($fileReferences as $fileReference) {
$description = $fileReference->getDescription();
if ($description !== null && $description !== '') {
$linkedContent .= htmlspecialchars($description) . '<br />';
}
}
$itemContent .= $parentObject->linkEditContent($linkedContent, $row);
unset($linkedContent);
}
}
$drawItem = false;
}
}
}
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Preview;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
/**
* Contains a preview rendering for the page module of CType="image"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class ImagePreviewRenderer extends StandardContentPreviewRenderer
{
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$row = $item->getRecord();
$content = $this->linkEditContent(BackendUtility::thumbCode($row, 'tt_content', 'image', '', '', null, 0, '', '', false), $row);
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'image', $row);
if (!empty($fileReferences)) {
$linkedContent = '';
foreach ($fileReferences as $fileReference) {
$description = $fileReference->getDescription();
if ($description !== null && $description !== '') {
$linkedContent .= htmlspecialchars($description) . '<br />';
}
}
$content .= $this->linkEditContent($linkedContent, $row);
}
return $content;
}
}
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
......@@ -13,39 +15,20 @@
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Hooks\PageLayoutView;
namespace TYPO3\CMS\Frontend\Preview;
use TYPO3\CMS\Backend\View\PageLayoutView;
use TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
/**
* Contains a preview rendering for the page module of CType="text"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class TextPreviewRenderer implements PageLayoutViewDrawItemHookInterface
class TextPreviewRenderer extends StandardContentPreviewRenderer
{
/**
* Preprocesses the preview rendering of the content element "text".
*
* @param \TYPO3\CMS\Backend\View\PageLayoutView $parentObject Calling parent object
* @param bool $drawItem Whether to draw the item using the default functionalities
* @param string $headerContent Header content
* @param string $itemContent Item content
* @param array $row Record row of tt_content
*/
public function preProcess(
PageLayoutView &$parentObject,
&$drawItem,
&$headerContent,
&$itemContent,
array &$row
) {
if ($row['CType'] === 'text') {
if ($row['bodytext']) {
$itemContent .= $parentObject->linkEditContent($parentObject->renderText($row['bodytext']), $row) . '<br />';
}
$drawItem = false;
}
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$row = $item->getRecord();
return $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
}
}
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Frontend\Preview;
use TYPO3\CMS\Backend\Preview\StandardContentPreviewRenderer;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Backend\View\BackendLayout\Grid\GridColumnItem;
/**
* Contains a preview rendering for the page module of CType="textmedia"
* @internal this is a concrete TYPO3 hook implementation and solely used for EXT:frontend and not part of TYPO3's Core API.
*/
class TextmediaPreviewRenderer extends StandardContentPreviewRenderer
{
public function renderPageModulePreviewContent(GridColumnItem $item): string
{
$content = '';
$row = $item->getRecord();
if ($row['bodytext']) {
$content = $this->linkEditContent($this->renderText($row['bodytext']), $row) . '<br />';
}
if ($row['assets']) {
$content .= $this->linkEditContent(BackendUtility::thumbCode($row, 'tt_content', 'assets', '', '', null, 0, '', '', false), $row);
$fileReferences = BackendUtility::resolveFileReferences('tt_content', 'assets', $row);
if (!empty($fileReferences))