[FEATURE] Form: "Redirect" postprocessor 07/18307/8
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 8 Aug 2013 18:58:05 +0000 (20:58 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 8 Aug 2013 18:58:50 +0000 (20:58 +0200)
* Implements a basic postprocessor to perform a redirect.
* Adds it to the form-wizard.
* Enables prepared ExtJS-code for removing a postprocessor.

Resolves: #44482
Resolves: #38094
Releases: 6.2
Change-Id: I7e09bc9aa9821ac20e890343eb95c34c010dfba3
Reviewed-on: https://review.typo3.org/18307
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/form/Classes/PostProcess/RedirectPostProcessor.php [new file with mode: 0644]
typo3/sysext/form/Classes/View/Wizard/WizardView.php
typo3/sysext/form/Configuration/PageTS/modWizards.ts
typo3/sysext/form/Resources/Private/Language/locallang_wizard.xlf
typo3/sysext/form/Resources/Public/JavaScript/Wizard/Elements/Basic/Form.js
typo3/sysext/form/Resources/Public/JavaScript/Wizard/Viewport/Left/Form/PostProcessor.js
typo3/sysext/form/Resources/Public/JavaScript/Wizard/Viewport/Left/Form/PostProcessors/PostProcessor.js
typo3/sysext/form/Resources/Public/JavaScript/Wizard/Viewport/Left/Form/PostProcessors/Redirect.js [new file with mode: 0644]

diff --git a/typo3/sysext/form/Classes/PostProcess/RedirectPostProcessor.php b/typo3/sysext/form/Classes/PostProcess/RedirectPostProcessor.php
new file mode 100644 (file)
index 0000000..fdf5575
--- /dev/null
@@ -0,0 +1,102 @@
+<?php
+namespace TYPO3\CMS\Form\PostProcess;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Stefan Neufeind <info@speedpartner.de>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+/**
+ * The redirect post processor
+ */
+class RedirectPostProcessor implements \TYPO3\CMS\Form\PostProcess\PostProcessorInterface {
+
+       /**
+        * @var \TYPO3\CMS\Form\Domain\Model\Form
+        */
+       protected $form;
+
+       /**
+        * @var array
+        */
+       protected $typoScript;
+
+       /**
+        * @var \TYPO3\CMS\Form\Request
+        */
+       protected $requestHandler;
+
+       /**
+        * @var string
+        */
+       protected $destination;
+
+       /**
+        * @var array
+        */
+       protected $dirtyHeaders = array();
+
+       /**
+        * Constructor
+        *
+        * @param \TYPO3\CMS\Form\Domain\Model\Form $form Form domain model
+        * @param array $typoScript Post processor TypoScript settings
+        */
+       public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
+               $this->form = $form;
+               $this->typoScript = $typoScript;
+               $this->requestHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Request');
+       }
+
+       /**
+        * The main method called by the post processor
+        *
+        * @return string HTML message from this processor
+        */
+       public function process() {
+               $this->setDestination();
+               return $this->render();
+       }
+
+       /**
+        * Sets the redirect destination
+        *
+        * @return void
+        */
+       protected function setDestination() {
+               $this->destination = '';
+               if ($this->typoScript['destination']) {
+                       $urlConf = array('parameter' => $this->typoScript['destination']);
+                       $this->destination = $GLOBALS['TSFE']->cObj->typoLink_URL($urlConf);
+               }
+       }
+
+       /**
+        * Render the message after trying to send the mail
+        *
+        * @return string HTML message from the mail view
+        */
+       protected function render() {
+               \TYPO3\CMS\Core\Utility\HttpUtility::redirect($this->destination);
+               return '';
+       }
+}
+
+?>
index 6088f71..e38b9bb 100644 (file)
@@ -214,7 +214,8 @@ class WizardView extends \TYPO3\CMS\Form\View\Wizard\AbstractWizardView {
                        'Viewport/Left/Form/PostProcessor.js',
                        'Viewport/Left/Form/PostProcessors/PostProcessor.js',
                        'Viewport/Left/Form/PostProcessors/Dummy.js',
-                       'Viewport/Left/Form/PostProcessors/Mail.js'
+                       'Viewport/Left/Form/PostProcessors/Mail.js',
+                       'Viewport/Left/Form/PostProcessors/Redirect.js'
                );
                // Load ExtJS
                $this->pageRenderer->loadExtJS();
index a1fbf38..5e4bcf5 100644 (file)
@@ -154,11 +154,14 @@ prefix = tx_form
                                                        showProperties = accept, acceptcharset, action, class, dir, enctype, id, lang, method, name, style, title
                                                }
                                                postProcessor {
-                                                       showPostProcessors = mail
+                                                       showPostProcessors = mail, redirect
                                                        postProcessors {
                                                                mail {
                                                                        showProperties = recipientEmail, senderEmail, subject
                                                                }
+                                                               redirect {
+                                                                       showProperties = destination
+                                                               }
                                                        }
                                                }
                                        }
index 58e9c6c..5e16acc 100644 (file)
                        <trans-unit id="postprocessor_mail" xml:space="preserve">
                                <source>Send email</source>
                        </trans-unit>
+                       <trans-unit id="postprocessor_redirect" xml:space="preserve">
+                               <source>Redirect</source>
+                       </trans-unit>
                        <trans-unit id="postprocessor_dummy_title" xml:space="preserve">
                                <source>No post processor selected</source>
                        </trans-unit>
                        <trans-unit id="postprocessor_properties_subject" xml:space="preserve">
                                <source>Subject</source>
                        </trans-unit>
-                       <trans-unit id="postprocessor_mail" xml:space="preserve">
-                               <source>Send email</source>
+                       <trans-unit id="postprocessor_properties_destination" xml:space="preserve">
+                               <source>Destination to redirect to</source>
                        </trans-unit>
                        <trans-unit id="prefix_prefix" xml:space="preserve">
                                <source>Prefix</source>
index c6a7377..7658355 100644 (file)
@@ -89,6 +89,9 @@ TYPO3.Form.Wizard.Elements.Basic.Form = Ext.extend(TYPO3.Form.Wizard.Elements, {
                                        mail: {
                                                recipientEmail: '',
                                                senderEmail: ''
+                                       },
+                                       redirect: {
+                                               destination: ''
                                        }
                                }
                        }
index 4f362e1..001bdf8 100644 (file)
@@ -42,9 +42,7 @@ TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessor = Ext.extend(Ext.Panel, {
                        items: [{
                                xtype: 'typo3-form-wizard-viewport-left-form-postprocessors-dummy',
                                ref: 'dummy'
-                       }]
-                       // TODO: When there are more post processors, the dropdown should be visible
-                       /*,
+                       }],
                        tbar: [
                                {
                                        xtype: 'combo',
@@ -71,7 +69,7 @@ TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessor = Ext.extend(Ext.Panel, {
                                                }
                                        }
                                }
-                       ]*/
+                       ]
                };
 
                        // apply config
index b01446b..8365638 100644 (file)
@@ -104,16 +104,28 @@ TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.PostProcessor = Ext.extend(E
                                                }
                                        });
                                        break;
+                               case 'destination':
+                                       formItems.push({
+                                               fieldLabel: TYPO3.l10n.localize('postprocessor_properties_destination'),
+                                               name: 'destination',
+                                               allowBlank: false,
+                                               listeners: {
+                                                       'triggerclick': {
+                                                               scope: this,
+                                                               fn: this.storeValue
+                                                       }
+                                               }
+                                       });
+                                       break;
                        }
                }, this);
 
-               // TODO: Add the remove button when more post processors are available
-               /*formItems.push({
+               formItems.push({
                        xtype: 'button',
                        text: TYPO3.l10n.localize('button_remove'),
                        handler: this.removePostProcessor,
                        scope: this
-               });*/
+               });
 
                var config = {
                        items: [
diff --git a/typo3/sysext/form/Resources/Public/JavaScript/Wizard/Viewport/Left/Form/PostProcessors/Redirect.js b/typo3/sysext/form/Resources/Public/JavaScript/Wizard/Viewport/Left/Form/PostProcessors/Redirect.js
new file mode 100644 (file)
index 0000000..5ef78dd
--- /dev/null
@@ -0,0 +1,33 @@
+Ext.namespace('TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors');
+
+/**
+ * The redirect post processor
+ *
+ * @class TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.Redirect
+ * @extends TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.PostProcessor
+ */
+TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.Redirect = Ext.extend(TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.PostProcessor, {
+       /**
+        * @cfg {String} processor
+        *
+        * The name of this processor
+        */
+       processor: 'redirect',
+
+       /**
+        * Constructor
+        *
+        * Add the configuration object to this component
+        * @param config
+        */
+       constructor: function(config) {
+               Ext.apply(this, {
+                       configuration: {
+                               destination: '',
+                       }
+               });
+               TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.Redirect.superclass.constructor.apply(this, arguments);
+       }
+});
+
+Ext.reg('typo3-form-wizard-viewport-left-form-postprocessors-redirect', TYPO3.Form.Wizard.Viewport.Left.Form.PostProcessors.Redirect);