Commit 87b78a63 authored by Ralf Zimmermann's avatar Ralf Zimmermann Committed by Christian Kuhn
Browse files

[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: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Björn Jacob's avatarBjoern Jacob <bjoern.jacob@tritum.de>
Tested-by: Björn Jacob's avatarBjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 973ffb7a
<?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'];
}
}
......@@ -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>
......
......@@ -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',
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment