[TASK] EXT:form - Add CE preview for form plugins 22/51422/5
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Wed, 25 Jan 2017 10:58:06 +0000 (11:58 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 26 Jan 2017 15:53:45 +0000 (16:53 +0100)
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>
typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php [new file with mode: 0644]
typo3/sysext/form/Resources/Private/Language/Database.xlf
typo3/sysext/form/ext_localconf.php

diff --git a/typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php b/typo3/sysext/form/Classes/Hooks/FormPagePreviewRenderer.php
new file mode 100644 (file)
index 0000000..9aed0b4
--- /dev/null
@@ -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'];
+    }
+}
index 2ed8668..36364dd 100644 (file)
                 <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>
index a5ea5e7..f008f51 100644 (file)
@@ -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',