[FEATURE] EXT:form - Add the "Confirmation" finisher to the form editor 07/52007/5
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Sat, 11 Mar 2017 14:45:41 +0000 (15:45 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Thu, 17 Aug 2017 08:41:11 +0000 (10:41 +0200)
Make the "Confirmation message" finisher available within the form editor.

The BE-editor can choose between 2 possibilities:

* Enter the confirmation message (plain text) into a textarea.
* Select a content element that is rendered instead.

Resolves: #80187
Releases: master
Change-Id: Ic163964669c95c98a38726f5d814b696d6e7f7bc
Reviewed-on: https://review.typo3.org/52007
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Mona Muzaffar <mona.muzaffar@gmx.de>
Reviewed-by: Martin Kutschker <martin.kutschker@ymail.com>
Tested-by: Martin Kutschker <martin.kutschker@ymail.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/core/Documentation/Changelog/master/Feature-80187-ExtFormAddConfirmationFinisherToTheFormEditor.rst [new file with mode: 0644]
typo3/sysext/form/Classes/Domain/Finishers/ConfirmationFinisher.php
typo3/sysext/form/Configuration/Yaml/BaseSetup.yaml
typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml
typo3/sysext/form/Resources/Private/Backend/Partials/FormEditor/Inspector/TextareaEditor.html
typo3/sysext/form/Resources/Private/Language/Database.xlf
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js
typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js

diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-80187-ExtFormAddConfirmationFinisherToTheFormEditor.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-80187-ExtFormAddConfirmationFinisherToTheFormEditor.rst
new file mode 100644 (file)
index 0000000..73f6847
--- /dev/null
@@ -0,0 +1,44 @@
+.. include:: ../../Includes.txt
+
+====================================================================
+Feature: #80187 - Add the "Confirmation" finisher to the form editor
+====================================================================
+
+See :issue:`80187`
+
+Description
+===========
+
+The "Confirmation Message" finisher is now editable through the form editor.
+The "Confirmation Message" finisher is now able to render a content element as message.
+The option "contentElementUid" can be used to render a content element:
+
+.. code-block:: typoscript
+
+    finishers:
+      -
+        identifier: Confirmation
+        options:
+          contentElementUid: 765
+
+If contentElementUid is set, the option "message" will be ignored.
+
+The option "typoscriptObjectPath" can be used to render the content element
+through a typoscript lib (default: 'lib.tx_form.contentElementRendering')
+
+.. code-block:: typoscript
+
+    finishers:
+      -
+        identifier: Confirmation
+        options:
+          contentElementUid: 765
+          typoscriptObjectPath: 'lib.tx_myext.customContentElementRendering'
+
+Impact
+======
+
+The "Confirmation Message" finisher is now editable through the form editor.
+The "Confirmation Message" finisher is now able to render a content element as message.
+
+.. index:: Backend, Frontend, ext:form
\ No newline at end of file
index 07188b0..4ec6b2a 100644 (file)
@@ -17,7 +17,10 @@ namespace TYPO3\CMS\Form\Domain\Finishers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
 use TYPO3\CMS\Form\Domain\Finishers\Exception\FinisherException;
+use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
 
 /**
  * A simple finisher that outputs a given text
@@ -47,9 +50,39 @@ class ConfirmationFinisher extends AbstractFinisher
      */
     protected $defaultOptions = [
         'message' => 'The form has been submitted.',
+        'contentElementUid' => 0,
+        'typoscriptObjectPath' => 'lib.tx_form.contentElementRendering'
     ];
 
     /**
+     * @var array
+     */
+    protected $typoScriptSetup = [];
+
+    /**
+     * @var ConfigurationManagerInterface
+     */
+    protected $configurationManager;
+
+    /**
+     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
+     * @return void
+     */
+    public function injectConfigurationManager(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager)
+    {
+        $this->configurationManager = $configurationManager;
+        $this->typoScriptSetup = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_FULL_TYPOSCRIPT);
+    }
+
+    /**
+     * @param ContentObjectRenderer $contentObjectRenderer
+     */
+    public function injectContentObjectRenderer(ContentObjectRenderer $contentObjectRenderer)
+    {
+        $this->contentObjectRenderer = $contentObjectRenderer;
+    }
+
+    /**
      * Executes this finisher
      * @see AbstractFinisher::execute()
      *
@@ -58,7 +91,29 @@ class ConfirmationFinisher extends AbstractFinisher
     protected function executeInternal()
     {
         $formRuntime = $this->finisherContext->getFormRuntime();
-        $message = $this->parseOption('message');
+
+        $contentElementUid = (int)$this->parseOption('contentElementUid');
+        $typoscriptObjectPath = $this->parseOption('typoscriptObjectPath');
+        if ($contentElementUid > 0) {
+            $pathSegments = GeneralUtility::trimExplode('.', $typoscriptObjectPath);
+            $lastSegment = array_pop($pathSegments);
+            $setup = $this->typoScriptSetup;
+            foreach ($pathSegments as $segment) {
+                if (!array_key_exists(($segment . '.'), $setup)) {
+                    throw new FinisherException(
+                        sprintf('TypoScript object path "%s" does not exist', $typoscriptObjectPath),
+                        1489238980
+                    );
+                }
+                $setup = $setup[$segment . '.'];
+            }
+            $this->contentObjectRenderer->start([$contentElementUid], '');
+            $this->contentObjectRenderer->setCurrentVal((string)$contentElementUid);
+            $message = $this->contentObjectRenderer->cObjGetSingle($setup[$lastSegment], $setup[$lastSegment . '.']);
+        } else {
+            $message = $this->parseOption('message');
+        }
+
         $formRuntime->getResponse()->setContent($message);
     }
 }
index 8211253..99d2e75 100644 (file)
@@ -240,6 +240,8 @@ TYPO3:
               implementationClassName: 'TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher'
               #options:
                 #message: ''
+                #contentElementUid: 0
+                #typoscriptObjectPath: 'lib.tx_form.contentElementRendering'
 
             EmailToSender:
               __inheritances:
index c62d376..c9dbde1 100644 (file)
@@ -184,6 +184,9 @@ TYPO3:
                       50:
                         value: 'DeleteUploads'
                         label: 'formEditor.elements.Form.editor.finishers.DeleteUploads.label'
+                      60:
+                        value: 'Confirmation'
+                        label: 'formEditor.elements.Form.editor.finishers.Confirmation.label'
 
                 propertyCollections:
                   finishers:
@@ -273,6 +276,23 @@ TYPO3:
                           10: 'TYPO3.CMS.Form.mixins.formElementMixins.BaseCollectionEditorsMixin'
                         100:
                           label: 'formEditor.elements.Form.finisher.Confirmation.editor.header.label'
+                        200:
+                          identifier: 'contentElement'
+                          templateName: 'Inspector-Typo3WinBrowserEditor'
+                          label: 'formEditor.elements.Form.finisher.Confirmation.editor.contentElement.label'
+                          buttonLabel: 'formEditor.elements.Form.finisher.Confirmation.editor.contentElement.buttonLabel'
+                          browsableType: tt_content
+                          propertyPath: 'options.contentElementUid'
+                          propertyValidatorsMode: 'OR'
+                          propertyValidators:
+                            10: 'IntegerOrEmpty'
+                            20: 'FormElementIdentifierWithinCurlyBracesExclusive'
+                        300:
+                          identifier: 'message'
+                          templateName: 'Inspector-TextareaEditor'
+                          label: 'formEditor.elements.Form.finisher.Confirmation.editor.message.label'
+                          propertyPath: 'options.message'
+                          fieldExplanationText: 'formEditor.elements.Form.finisher.Confirmation.editor.message.fieldExplanationText'
 
                     60:
                       identifier: 'Closure'
@@ -725,6 +745,7 @@ TYPO3:
                 predefinedDefaults:
                   options:
                     message: ''
+                    contentElementUid: ''
 
             FlashMessage:
               formEditor:
index 28e65d2..ab96bbc 100644 (file)
@@ -5,6 +5,7 @@
                <div class="t3-form-controls" data-identifier="inspectorEditorControlsWrapper">
                        <textarea data-template-property="propertyPath" class="form-control" />
                </div>
+               <span data-template-property="fieldExplanationText" />
        </div>
 </div>
 </html>
index 74bea26..fcd8442 100644 (file)
             <trans-unit id="formEditor.elements.Form.editor.finishers.DeleteUploads.label" xml:space="preserve">
                 <source>Delete uploads</source>
             </trans-unit>
+            <trans-unit id="formEditor.elements.Form.editor.finishers.Confirmation.label" xml:space="preserve">
+                <source>Confirmation message</source>
+            </trans-unit>
 
             <trans-unit id="formEditor.elements.Form.finisher.EmailToSender.editor.header.label" xml:space="preserve">
                 <source>Send email (to website visitor)</source>
             <trans-unit id="formEditor.elements.Form.finisher.DeleteUploads.editor.header.label" xml:space="preserve">
                 <source>Delete uploads</source>
             </trans-unit>
+
             <trans-unit id="formEditor.elements.Form.finisher.Confirmation.editor.header.label" xml:space="preserve">
                 <source>Confirmation message</source>
             </trans-unit>
+            <trans-unit id="formEditor.elements.Form.finisher.Confirmation.editor.contentElement.label" xml:space="preserve">
+                <source>Content element uid</source>
+            </trans-unit>
+            <trans-unit id="formEditor.elements.Form.finisher.Confirmation.editor.contentElement.buttonLabel" xml:space="preserve">
+                <source>tt_content</source>
+            </trans-unit>
+            <trans-unit id="formEditor.elements.Form.finisher.Confirmation.editor.message.label" xml:space="preserve">
+                <source>Text</source>
+            </trans-unit>
+            <trans-unit id="formEditor.elements.Form.finisher.Confirmation.editor.message.fieldExplanationText" xml:space="preserve">
+                <source>Will be ignored if "Content element" is set</source>
+            </trans-unit>
+
             <trans-unit id="formEditor.elements.Form.finisher.Closure.editor.header.label" xml:space="preserve">
                 <source>Execute a closure</source>
             </trans-unit>
index fa1931b..e7f6973 100644 (file)
@@ -419,7 +419,7 @@ define(['jquery',
             sortableDomElement.addClass(getHelper().getDomElementClassName('sortable')).sortable({
                 revert: 'true',
                 items: getHelper().getDomElementClassName('collectionElement', true),
-                cancel: getHelper().getDomElementClassName('jQueryUiStateDisabled', true) + ',input,select',
+                cancel: getHelper().getDomElementClassName('jQueryUiStateDisabled', true) + ',input,textarea,select',
                 delay: 200,
                 update: function(e, o) {
                     var dataAttributeName, nextCollectionElementIdentifier, movedCollectionElementIdentifier, previousCollectionElementIdentifier;
index cc4813a..c162a21 100644 (file)
@@ -209,6 +209,12 @@ define(['jquery',
                 }
             });
 
+            getFormEditorApp().addPropertyValidationValidator('IntegerOrEmpty', function(formElement, propertyPath) {
+                if (formElement.get(propertyPath).length > 0 && !$.isNumeric(formElement.get(propertyPath))) {
+                    return getFormEditorApp().getFormElementPropertyValidatorDefinition('Integer')['errorMessage'] || 'invalid value';
+                }
+            });
+
             getFormEditorApp().addPropertyValidationValidator('NaiveEmail', function(formElement, propertyPath) {
                 if (!formElement.get(propertyPath).match(/\S+@\S+\.\S+/)) {
                     return getFormEditorApp().getFormElementPropertyValidatorDefinition('NaiveEmail')['errorMessage'] || 'invalid value';