From 87b78a638fec4252832c820811646a5ce6da8abe Mon Sep 17 00:00:00 2001 From: Ralf Zimmermann <ralf.zimmermann@tritum.de> Date: Wed, 25 Jan 2017 11:58:06 +0100 Subject: [PATCH] [TASK] EXT:form - Add CE preview for form plugins Render the form label or a placeholder text (if no form is selected) within the page module. Resolves: #78834 Releases: master Change-Id: I5519ce8bec7ae077d22328ff0ad70b29aa1b5af7 Reviewed-on: https://review.typo3.org/51422 Tested-by: TYPO3com <no-reply@typo3.com> Reviewed-by: Bjoern Jacob <bjoern.jacob@tritum.de> Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> --- .../Classes/Hooks/FormPagePreviewRenderer.php | 86 +++++++++++++++++++ .../Resources/Private/Language/Database.xlf | 4 + typo3/sysext/form/ext_localconf.php | 4 + 3 files changed, 94 insertions(+) create mode 100644 typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php diff --git a/typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php b/typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php new file mode 100644 index 000000000000..9aed0b4ff023 --- /dev/null +++ b/typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php @@ -0,0 +1,86 @@ +<?php +declare(strict_types=1); +namespace TYPO3\CMS\Form\Hooks; + +/* + * 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! + */ + +use TYPO3\CMS\Core\Utility\GeneralUtility; +use TYPO3\CMS\Extbase\Object\ObjectManager; +use TYPO3\CMS\Extbase\Service\FlexFormService; +use TYPO3\CMS\Form\Mvc\Persistence\FormPersistenceManagerInterface; +use TYPO3\CMS\Lang\LanguageService; + +/** + * Contains a preview rendering for the page module of CType="form_formframework" + */ +class FormPagePreviewRenderer implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface +{ + /** + * 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 + * @return void + */ + public function preProcess( + \TYPO3\CMS\Backend\View\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 />'; + + $flexFormData = GeneralUtility::makeInstance(FlexFormService::class) + ->convertFlexFormContentToArray($row['pi_flexform']); + + if (!empty($flexFormData['settings']['persistenceIdentifier'])) { + $persistenceIdentifier = $flexFormData['settings']['persistenceIdentifier']; + if (empty($persistenceIdentifier)) { + $formLabel = $this->getLanguageService()->sL( + 'LLL:EXT:form/Resources/Private/Language/Database.xlf:tt_content.preview.noPersistenceIdentifier' + ); + } else { + $formPersistenceManager = GeneralUtility::makeInstance(ObjectManager::class)->get(FormPersistenceManagerInterface::class); + $formDefinition = $formPersistenceManager->load($persistenceIdentifier); + $formLabel = $formDefinition['label']; + } + } else { + $formLabel = $this->getLanguageService()->sL( + 'LLL:EXT:form/Resources/Private/Language/Database.xlf:tt_content.preview.noPersistenceIdentifier' + ); + } + + $itemContent .= $parentObject->linkEditContent( + $parentObject->renderText($formLabel), + $row + ) . '<br />'; + + $drawItem = false; + } + } + + /** + * @return LanguageService + */ + protected function getLanguageService(): LanguageService + { + return $GLOBALS['LANG']; + } +} diff --git a/typo3/sysext/form/Resources/Private/Language/Database.xlf b/typo3/sysext/form/Resources/Private/Language/Database.xlf index 2ed866814708..36364dd35d88 100644 --- a/typo3/sysext/form/Resources/Private/Language/Database.xlf +++ b/typo3/sysext/form/Resources/Private/Language/Database.xlf @@ -20,6 +20,10 @@ <source>Override finisher settings</source> </trans-unit> + <trans-unit id="tt_content.preview.noPersistenceIdentifier" xml:space="preserve"> + <source>No form selected.</source> + </trans-unit> + <trans-unit id="tt_content.finishersDefinition.EmailToSender.label" xml:space="preserve"> <source>Email to sender</source> </trans-unit> diff --git a/typo3/sysext/form/ext_localconf.php b/typo3/sysext/form/ext_localconf.php index a5ea5e710d70..f008f51d186f 100644 --- a/typo3/sysext/form/ext_localconf.php +++ b/typo3/sysext/form/ext_localconf.php @@ -30,6 +30,10 @@ 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 a bunch of icons to icon registry $iconIdentifiers = [ 'advanced-password', -- GitLab