From b49e638283e682e0808f49c09210ba3f302b7f61 Mon Sep 17 00:00:00 2001 From: Ralf Zimmermann <ralf.zimmermann@tritum.de> Date: Sat, 11 Mar 2017 15:45:41 +0100 Subject: [PATCH] [FEATURE] EXT:form - Add the "Confirmation" finisher to the form editor 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> --- ...AddConfirmationFinisherToTheFormEditor.rst | 44 ++++++++++++++ .../Domain/Finishers/ConfirmationFinisher.php | 57 ++++++++++++++++++- .../form/Configuration/Yaml/BaseSetup.yaml | 2 + .../Configuration/Yaml/FormEditorSetup.yaml | 21 +++++++ .../FormEditor/Inspector/TextareaEditor.html | 1 + .../Resources/Private/Language/Database.xlf | 17 ++++++ .../Backend/FormEditor/InspectorComponent.js | 2 +- .../Backend/FormEditor/ViewModel.js | 6 ++ 8 files changed, 148 insertions(+), 2 deletions(-) create mode 100644 typo3/sysext/core/Documentation/Changelog/master/Feature-80187-ExtFormAddConfirmationFinisherToTheFormEditor.rst 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 index 000000000000..73f6847e32dc --- /dev/null +++ b/typo3/sysext/core/Documentation/Changelog/master/Feature-80187-ExtFormAddConfirmationFinisherToTheFormEditor.rst @@ -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 diff --git a/typo3/sysext/form/Classes/Domain/Finishers/ConfirmationFinisher.php b/typo3/sysext/form/Classes/Domain/Finishers/ConfirmationFinisher.php index 07188b0d6912..4ec6b2a72b5a 100644 --- a/typo3/sysext/form/Classes/Domain/Finishers/ConfirmationFinisher.php +++ b/typo3/sysext/form/Classes/Domain/Finishers/ConfirmationFinisher.php @@ -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,8 +50,38 @@ 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); } } diff --git a/typo3/sysext/form/Configuration/Yaml/BaseSetup.yaml b/typo3/sysext/form/Configuration/Yaml/BaseSetup.yaml index 821125314f37..99d2e754c10a 100644 --- a/typo3/sysext/form/Configuration/Yaml/BaseSetup.yaml +++ b/typo3/sysext/form/Configuration/Yaml/BaseSetup.yaml @@ -240,6 +240,8 @@ TYPO3: implementationClassName: 'TYPO3\CMS\Form\Domain\Finishers\ConfirmationFinisher' #options: #message: '' + #contentElementUid: 0 + #typoscriptObjectPath: 'lib.tx_form.contentElementRendering' EmailToSender: __inheritances: diff --git a/typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml b/typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml index c62d37604e4d..c9dbde1e398c 100644 --- a/typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml +++ b/typo3/sysext/form/Configuration/Yaml/FormEditorSetup.yaml @@ -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: diff --git a/typo3/sysext/form/Resources/Private/Backend/Partials/FormEditor/Inspector/TextareaEditor.html b/typo3/sysext/form/Resources/Private/Backend/Partials/FormEditor/Inspector/TextareaEditor.html index 28e65d2c4513..ab96bbc2c474 100644 --- a/typo3/sysext/form/Resources/Private/Backend/Partials/FormEditor/Inspector/TextareaEditor.html +++ b/typo3/sysext/form/Resources/Private/Backend/Partials/FormEditor/Inspector/TextareaEditor.html @@ -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> diff --git a/typo3/sysext/form/Resources/Private/Language/Database.xlf b/typo3/sysext/form/Resources/Private/Language/Database.xlf index 74bea26e9c24..fcd844204daa 100644 --- a/typo3/sysext/form/Resources/Private/Language/Database.xlf +++ b/typo3/sysext/form/Resources/Private/Language/Database.xlf @@ -442,6 +442,9 @@ <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> @@ -569,9 +572,23 @@ <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> diff --git a/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js b/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js index fa1931b8f515..e7f6973808cc 100644 --- a/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js +++ b/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/InspectorComponent.js @@ -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; diff --git a/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js b/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js index cc4813a00c69..c162a21bfd3a 100644 --- a/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js +++ b/typo3/sysext/form/Resources/Public/JavaScript/Backend/FormEditor/ViewModel.js @@ -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'; -- GitLab