[BUGFIX] EXT:form - wrong attribute handling 71/43471/24
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Mon, 28 Sep 2015 17:57:36 +0000 (19:57 +0200)
committerGeorg Ringer <georg.ringer@gmail.com>
Mon, 28 Sep 2015 19:17:54 +0000 (21:17 +0200)
* centralize the attribute rendering method
* fix the attribute overlay methods
** fix: "select" labels remains empty
** fix: "textblock" remains empty

Resolves: #69957
Releases: master
Change-Id: I60554dbdf1eb8a25b9dfad820a2bc7bd20704199
Reviewed-on: http://review.typo3.org/43471
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
21 files changed:
typo3/sysext/form/Classes/Controller/FrontendController.php
typo3/sysext/form/Classes/Domain/Builder/ElementBuilder.php
typo3/sysext/form/Classes/Domain/Builder/FormBuilder.php
typo3/sysext/form/Classes/Domain/Builder/ValidationBuilder.php
typo3/sysext/form/Classes/Domain/Model/Configuration.php
typo3/sysext/form/Classes/Domain/Validator/AbstractValidator.php
typo3/sysext/form/Classes/Hooks/HandleIncomingFormValues.php
typo3/sysext/form/Classes/PostProcess/MailPostProcessor.php
typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php
typo3/sysext/form/Classes/Utility/FormUtility.php
typo3/sysext/form/Configuration/TypoScript/setup.txt
typo3/sysext/form/Resources/Private/Partials/Compatibility/Confirmation/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Html/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/PostProcessor/Mail/Plain/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Compatibility/Show/FlatElements/Textblock.html
typo3/sysext/form/Resources/Private/Partials/Default/Confirmation/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Default/PostProcessor/Mail/Html/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Default/PostProcessor/Mail/Plain/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Default/Show/FlatElements/Textarea.html
typo3/sysext/form/Resources/Private/Partials/Default/Show/FlatElements/Textblock.html

index 86d3ed6..d08058b 100755 (executable)
@@ -20,6 +20,7 @@ use TYPO3\CMS\Form\Mvc\Controller\ControllerContext;
 use TYPO3\CMS\Form\Domain\Builder\FormBuilder;
 use TYPO3\CMS\Form\Domain\Builder\ValidationBuilder;
 use TYPO3\CMS\Form\Domain\Model\Configuration;
+use TYPO3\CMS\Form\Utility\FormUtility;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 
 /**
@@ -43,7 +44,7 @@ class FrontendController extends ActionController {
        protected $sessionUtility;
 
        /**
-        * @var \TYPO3\CMS\Form\Utility\FormUtility
+        * @var FormUtility
         */
        protected $formUtility;
 
@@ -80,23 +81,18 @@ class FrontendController extends ActionController {
        }
 
        /**
-        * @param \TYPO3\CMS\Form\Utility\FormUtility $formUtility
-        * @return void
-        */
-       public function injectFormUtility(\TYPO3\CMS\Form\Utility\FormUtility $formUtility) {
-               $this->formUtility = $formUtility;
-       }
-
-       /**
         * initialize action
         *
         * @return void
         */
        protected function initializeAction() {
                $this->configuration = Configuration::create()->setTypoScript($this->settings['typoscript']);
+               $this->formUtility = FormUtility::create($this->configuration);
                $this->validationBuilder = ValidationBuilder::create($this->configuration);
+               $this->validationBuilder->setFormUtility($this->formUtility);
                $this->formBuilder = FormBuilder::create($this->configuration);
                $this->formBuilder->setValidationBuilder($this->validationBuilder);
+               $this->formBuilder->setFormUtility($this->formUtility);
                $this->typoscript = $this->settings['typoscript'];
 
                        // uploaded file storage
@@ -205,15 +201,10 @@ class FrontendController extends ActionController {
                $this->sessionUtility->storeSession();
                $this->view->assign('model', $form);
 
-               $confirmationMessage = NULL;
-               $confirmationMessageType = NULL;
-               if (isset($this->typoscript['confirmation']['message.'])) {
-                       $confirmationMessage = $this->typoscript['confirmation']['message.'];
-                       $confirmationMessageType = $this->typoscript['confirmation']['message'];
-               }
-               $message = $this->renderConfirmationMessage(
-                       $confirmationMessage,
-                       $confirmationMessageType
+               $message = $this->formUtility->renderItem(
+                       $this->typoscript['confirmation.']['message.'],
+                       $this->typoscript['confirmation.']['message'],
+                       LocalizationUtility::translate('tx_form_view_confirmation.message', 'form')
                );
                $this->view->assign('message', $message);
        }
@@ -321,43 +312,4 @@ class FrontendController extends ActionController {
                        $baseConjunctionValidator->addValidator($modelValidator);
                }
        }
-
-       /**
-        * Render the message for the confirmation page
-        *
-        * @param mixed $message Message as string or TS
-        * @param NULL|string $type Name of the cObj
-        * @return string XHTML string containing the message
-        */
-       protected function renderConfirmationMessage($message = NULL, $type = NULL) {
-               if ($this->configuration->getContentElementRendering()) {
-                       if (
-                               $type !== NULL
-                               && $message !== NULL
-                       ) {
-                               $value = $message;
-                       } elseif ($message !== NULL) {
-                               $value = $message;
-                               $type = 'TEXT';
-                       } else {
-                               $value['wrap'] = '<p>|</p>';
-                               $value['value'] = LocalizationUtility::translate('tx_form_view_confirmation.message', 'form');
-                               $type = 'TEXT';
-                       }
-                       $message = $this->formUtility->renderContentObject(
-                               $type,
-                               $value
-                       );
-               } else {
-                       if (isset($this->typoscript['message.']['value'])) {
-                               $message = $this->typoscript['message.']['value'];
-                       } elseif (isset($this->typoscript['message.']['data'])) {
-                               $message = LocalizationUtility::translate($this->typoscript['message.']['data'], 'form');
-                       } else {
-                               $message = $this->typoscript['message'];
-                       }
-               }
-               return $message;
-       }
-
 }
index c76eb39..fec3165 100644 (file)
@@ -39,11 +39,6 @@ class ElementBuilder {
        }
 
        /**
-        * @var \TYPO3\CMS\Form\Utility\FormUtility
-        */
-       protected $formUtility;
-
-       /**
         * @var \TYPO3\CMS\Form\Domain\Repository\TypoScriptRepository
         */
        protected $typoScriptRepository;
@@ -79,14 +74,6 @@ class ElementBuilder {
        protected $element;
 
        /**
-        * @param \TYPO3\CMS\Form\Utility\FormUtility $formUtility
-        * @return void
-        */
-       public function injectFormUtility(\TYPO3\CMS\Form\Utility\FormUtility $formUtility) {
-               $this->formUtility = $formUtility;
-       }
-
-       /**
         * @param \TYPO3\CMS\Form\Domain\Repository\TypoScriptRepository $typoScriptRepository
         * @return void
         */
@@ -188,15 +175,45 @@ class ElementBuilder {
        public function overlayUserdefinedHtmlAttributeValues() {
                foreach ($this->htmlAttributes as $attributeName => $attributeValue) {
                        $attributeNameWithoutDot = rtrim($attributeName, '.');
-                       if (
-                               isset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot])
-                               || isset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'])
-                       ) {
-                               $returnValue = $this->renderAttributeValue($attributeName, array());
-                               $attributeValue = $returnValue['attributeValue'];
-                               $this->htmlAttributes[$attributeNameWithoutDot] = $attributeValue;
-                               unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot]);
+                       $attributeNameToSet = $attributeNameWithoutDot;
+                       $rendered = FALSE;
+                       /* If the attribute exists in the user configured typoscript */
+                       if ($this->arrayKeyExists($attributeName, $this->userConfiguredElementTyposcript)) {
+                               if ($this->formBuilder->getConfiguration()->getCompatibility()) {
+                                       $newAttributeName = $this->formBuilder->getCompatibilityService()->getNewAttributeName(
+                                               $this->element->getElementType(),
+                                               $attributeNameWithoutDot
+                                       );
+                                       /* Should the attribute be renamed? */
+                                       if ($newAttributeName !== $attributeNameWithoutDot) {
+                                               $attributeNameToSet = $newAttributeName;
+                                               /* If the renamed attribute already exists in the user configured typoscript */
+                                               if ($this->arrayKeyExists($newAttributeName, $this->userConfiguredElementTyposcript)) {
+                                                       $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                                                               $this->userConfiguredElementTyposcript[$newAttributeName . '.'],
+                                                               $this->userConfiguredElementTyposcript[$newAttributeName]
+                                                       );
+                                                       /* set renamed attribute name with the value of the renamed attribute */
+                                                       $this->htmlAttributes[$newAttributeName] = $attributeValue;
+                                                       /* unset the renamed attribute */
+                                                       unset($this->userConfiguredElementTyposcript[$newAttributeName . '.']);
+                                                       unset($this->userConfiguredElementTyposcript[$newAttributeName]);
+                                                       $rendered = TRUE;
+                                               }
+                                       }
+                               }
+                       }
+                       if ($rendered === FALSE) {
+                               if ($this->arrayKeyExists($attributeNameWithoutDot, $this->userConfiguredElementTyposcript)) {
+                                       $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                                               $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'],
+                                               $this->userConfiguredElementTyposcript[$attributeNameWithoutDot]
+                                       );
+                                       $this->htmlAttributes[$attributeNameToSet] = $attributeValue;
+                               }
                        }
+                       unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.']);
+                       unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot]);
                }
 
                        // the prefix-* magic
@@ -216,10 +233,13 @@ class ElementBuilder {
                                        continue;
                                }
                                $attributeNameWithoutDot = rtrim($attributeName, '.');
-                               $returnValue = $this->renderAttributeValue($attributeName, $ignoreKeys);
-                               $attributeValue = $returnValue['attributeValue'];
-                               $ignoreKeys = $returnValue['ignoreKeys'];
+                               $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                                       $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'],
+                                       $this->userConfiguredElementTyposcript[$attributeNameWithoutDot]
+                               );
                                $this->htmlAttributes[$attributeNameWithoutDot] = $attributeValue;
+                               $ignoreKeys[$attributeNameWithoutDot . '.'] = TRUE;
+                               unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.']);
                                unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot]);
                                break;
                        }
@@ -296,24 +316,44 @@ class ElementBuilder {
                                $ignoreKeys[$attributeName . '.'] = TRUE;
                                continue;
                        }
-
+                       $attributeNameWithoutDot = rtrim($attributeName, '.');
+                       $attributeNameToSet = $attributeNameWithoutDot;
+                       $rendered = FALSE;
                        if ($this->formBuilder->getConfiguration()->getCompatibility()) {
-                               $returnValue = $this->formBuilder->getCompatibilityService()->remapOldAttributes(
+                               $newAttributeName = $this->formBuilder->getCompatibilityService()->getNewAttributeName(
                                        $this->element->getElementType(),
-                                       $attributeName,
-                                       $this->additionalArguments,
-                                       $this->userConfiguredElementTyposcript
+                                       $attributeNameWithoutDot
                                );
-                               $attributeName = $returnValue['attributeName'];
-                               $this->additionalArguments = $returnValue['additionalArguments'];
-                               $this->userConfiguredElementTyposcript = $returnValue['userConfiguredElementTyposcript'];
+                               /* Should the attribute be renamed? */
+                               if ($newAttributeName !== $attributeNameWithoutDot) {
+                                       $attributeNameToSet = $newAttributeName;
+                                       /* If the renamed attribute already exists in the user configured typoscript */
+                                       if ($this->arrayKeyExists($newAttributeName, $this->userConfiguredElementTyposcript)) {
+                                               $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                                                       $this->userConfiguredElementTyposcript[$newAttributeName . '.'],
+                                                       $this->userConfiguredElementTyposcript[$newAttributeName]
+                                               );
+                                               /* set renamed attribute name with the value of the renamed attribute */
+                                               $this->additionalArguments[$newAttributeName] = $attributeValue;
+                                               /* unset the renamed attribute */
+                                               $ignoreKeys[$newAttributeName . '.'] = TRUE;
+                                               $ignoreKeys[$newAttributeName] = TRUE;
+                                               unset($this->userConfiguredElementTyposcript[$newAttributeName . '.']);
+                                               unset($this->userConfiguredElementTyposcript[$newAttributeName]);
+                                               $rendered = TRUE;
+                                       }
+                               }
                        }
-
-                       $attributeNameWithoutDot = rtrim($attributeName, '.');
-                       $returnValue = $this->renderAttributeValue($attributeName, $ignoreKeys);
-                       $attributeValue = $returnValue['attributeValue'];
-                       $ignoreKeys = $returnValue['ignoreKeys'];
-                       $this->additionalArguments[$attributeNameWithoutDot] = $attributeValue;
+                       if ($rendered === FALSE) {
+                               $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                                       $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'],
+                                       $this->userConfiguredElementTyposcript[$attributeNameWithoutDot]
+                               );
+                               $this->additionalArguments[$attributeNameToSet] = $attributeValue;
+                               $ignoreKeys[$attributeNameToSet . '.'] = TRUE;
+                               $ignoreKeys[$attributeNameToSet] = TRUE;
+                       }
+                       unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.']);
                        unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot]);
                }
                        // remove "stdWrap." from "additionalArguments" on
@@ -335,7 +375,7 @@ class ElementBuilder {
        public function setNameAndId() {
                if (
                        $this->element->getParentElement()
-                       && (int)$this->typoScriptRepository->getModelConfigurationByScope($this->element->getParentElement()->getElementType(), 'childsInerhitName') == 1
+                       && (int)$this->typoScriptRepository->getModelConfigurationByScope($this->element->getParentElement()->getElementType(), 'childrenInheritName') == 1
                ) {
                        $this->htmlAttributes['name'] = $this->element->getParentElement()->getName();
                        $this->htmlAttributes['multiple'] = '1';
@@ -350,47 +390,6 @@ class ElementBuilder {
        }
 
        /**
-        * Render a attribute value
-        * Try to render it as content element if allowed
-        * Take care about short synthax like label.data = LLL:EXT: ...
-        * Try to translate label.data = LLL: ... stuff even if content
-        * elemet rendering is disabled
-        *
-        * @param string $attributeName
-        * @param array $ignoreKeys
-        * @return string
-        */
-       protected function renderAttributeValue($attributeName = '', array $ignoreKeys) {
-               $attributeNameWithoutDot = rtrim($attributeName, '.');
-               if (
-                       $this->formBuilder->getConfiguration()->getContentElementRendering()
-                       && isset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'])
-               ) {
-                       if ($attributeName !== $attributeNameWithoutDot) {
-                               $this->userConfiguredElementTyposcript[$attributeNameWithoutDot] = 'TEXT';
-                       }
-                       $attributeValue = $this->formUtility->renderContentObject(
-                               $this->userConfiguredElementTyposcript[$attributeNameWithoutDot],
-                               $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.']
-                       );
-                       $ignoreKeys[$attributeNameWithoutDot . '.'] = TRUE;
-                       unset($this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.']);
-               } else {
-                       if (isset($this->userConfiguredElementTyposcript[$attributeName]['value'])) {
-                               $attributeValue = $this->userConfiguredElementTyposcript[$attributeName]['value'];
-                       } elseif (isset($this->userConfiguredElementTyposcript[$attributeName]['data'])) {
-                               $attributeValue = LocalizationUtility::translate($this->userConfiguredElementTyposcript[$attributeName]['data'], 'form');
-                       } else {
-                               $attributeValue = $this->userConfiguredElementTyposcript[$attributeNameWithoutDot];
-                       }
-               }
-               return array(
-                       'attributeValue' => $attributeValue,
-                       'ignoreKeys' => $ignoreKeys,
-               );
-       }
-
-       /**
         * If the name is not defined it is automatically generated
         * using the following syntax: id-{element_counter}
         * The name attribute will be transformed if it contains some
@@ -402,7 +401,7 @@ class ElementBuilder {
         * @return string
         */
        public function sanitizeNameAttribute($name) {
-               $name = $this->formUtility->sanitizeNameAttribute($name);
+               $name = $this->formBuilder->getFormUtility()->sanitizeNameAttribute($name);
                if (empty($name)) {
                        $name = 'id-' . $this->element->getElementCounter();
                }
@@ -422,7 +421,7 @@ class ElementBuilder {
         * @return string
         */
        protected function sanitizeIdAttribute($id) {
-               $id = $this->formUtility->sanitizeIdAttribute($id);
+               $id = $this->formBuilder->getFormUtility()->sanitizeIdAttribute($id);
                if (empty($id)) {
                        $id = 'field-' . $this->element->getElementCounter();
                }
@@ -430,6 +429,19 @@ class ElementBuilder {
        }
 
        /**
+        * Check if a needle exists in a array.
+        *
+        * @param string $needle
+        * @param array $haystack
+        * @return boolean TRUE if found
+        */
+       protected function arrayKeyExists($needle, array $haystack = array()) {
+               return (
+                       isset($haystack[$needle]) || isset($haystack[$needle . '.'])
+               );
+       }
+
+       /**
         * Get the current html attributes
         *
         * @return array
index 1c6533e..acc2727 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Form\Domain\Model\Element;
 use TYPO3\CMS\Form\Domain\Model\ValidationElement;
 use TYPO3\CMS\Form\Utility\CompatibilityLayerUtility;
+use TYPO3\CMS\Form\Utility\FormUtility;
 use TYPO3\CMS\Form\Mvc\Controller\ControllerContext;
 use TYPO3\CMS\Form\Domain\Model\Configuration;
 
@@ -47,7 +48,7 @@ class FormBuilder {
        }
 
        /**
-        * @var \TYPO3\CMS\Form\Utility\FormUtility
+        * @var FormUtility
         */
        protected $formUtility;
 
@@ -107,14 +108,6 @@ class FormBuilder {
        protected $controllerContext;
 
        /**
-        * @param \TYPO3\CMS\Form\Utility\FormUtility $formUtility
-        * @return void
-        */
-       public function injectFormUtility(\TYPO3\CMS\Form\Utility\FormUtility $formUtility) {
-               $this->formUtility = $formUtility;
-       }
-
-       /**
         * @param \TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService
         * @return void
         */
@@ -204,6 +197,20 @@ class FormBuilder {
        }
 
        /**
+        * @return FormUtility
+        */
+       public function getFormUtility() {
+               return $this->formUtility;
+       }
+
+       /**
+        * @param FormUtility $formUtility
+        */
+       public function setFormUtility(FormUtility $formUtility) {
+               $this->formUtility = $formUtility;
+       }
+
+       /**
         * @return ValidationBuilder
         */
        public function getValidationBuilder() {
@@ -274,10 +281,6 @@ class FormBuilder {
        protected function reviveElement(Element $element, array $userConfiguredElementTypoScript, $elementType = '') {
                // @todo Check $userConfiguredElementTypoScript
 
-               if ($elementType === 'IMAGEBUTTON') {
-                       GeneralUtility::deprecationLog('EXT:form: The element IMAGEBUTTON is deprecated since TYPO3 CMS 7, will be removed with TYPO3 CMS 8.');
-               }
-
                $element->setElementType($elementType);
                $element->setElementCounter($this->elementCounter);
 
@@ -288,9 +291,9 @@ class FormBuilder {
                if ($element->getElementType() == 'CONTENTELEMENT') {
                        $attributeValue = '';
                        if ($this->configuration->getContentElementRendering()) {
-                               $attributeValue = $this->formUtility->renderContentObject(
-                                       $userConfiguredElementTypoScript['cObj'],
-                                       $userConfiguredElementTypoScript['cObj.']
+                               $attributeValue = $this->formUtility->renderItem(
+                                       $userConfiguredElementTypoScript['cObj.'],
+                                       $userConfiguredElementTypoScript['cObj']
                                );
                        }
                        $element->setAdditionalArguments(array(
index 3af02b4..a344436 100644 (file)
@@ -17,6 +17,7 @@ namespace TYPO3\CMS\Form\Domain\Builder;
 use TYPO3\CMS\Core\TypoScript\TemplateService;
 use TYPO3\CMS\Form\Domain\Model\Configuration;
 use TYPO3\CMS\Form\Domain\Validator\AbstractValidator;
+use TYPO3\CMS\Form\Utility\FormUtility;
 
 /**
  * Parse and hole all the validation rules
@@ -55,7 +56,7 @@ class ValidationBuilder {
        protected $typoScriptRepository;
 
        /**
-        * @var \TYPO3\CMS\Form\Utility\FormUtility
+        * @var FormUtility
         */
        protected $formUtility;
 
@@ -81,18 +82,17 @@ class ValidationBuilder {
        }
 
        /**
-        * @param \TYPO3\CMS\Form\Utility\FormUtility $formUtility
-        * @return void
+        * @param Configuration $configuration
         */
-       public function injectFormUtility(\TYPO3\CMS\Form\Utility\FormUtility $formUtility) {
-               $this->formUtility = $formUtility;
+       public function setConfiguration(Configuration $configuration) {
+               $this->configuration = $configuration;
        }
 
        /**
-        * @param Configuration $configuration
+        * @param FormUtility $formUtility
         */
-       public function setConfiguration(Configuration $configuration) {
-               $this->configuration = $configuration;
+       public function setFormUtility(FormUtility $formUtility) {
+               $this->formUtility = $formUtility;
        }
 
        /**
@@ -139,8 +139,8 @@ class ValidationBuilder {
                                        $validator = $this->objectManager->get($validatorClassName, $validatorOptions);
 
                                        if ($validator instanceof AbstractValidator) {
-                                               $validator->setConfiguration($this->configuration);
                                                $validator->setRawArgument($rawArgument);
+                                               $validator->setFormUtility($this->formUtility);
                                                $mandatoryMessage = $validator->renderMessage($ruleArguments['message.'], $ruleArguments['message']);
 
                                                $this->rules[$this->configuration->getPrefix()][$fieldName][] = array(
index 039a3d2..f745a4e 100644 (file)
@@ -172,13 +172,14 @@ class Configuration {
                if (!empty($this->typoScript['prefix'])) {
                        $this->setPrefix($this->typoScript['prefix']);
                }
-               // Determine compatibility behavior from global settings
-               $this->setCompatibility(
-                       $this->typoScriptRepository->getModelConfigurationByScope('FORM', 'compatibilityMode')
-               );
-               // Override compatibility behavior from current local settings
+               // Determine compatibility behavior
+               $this->setCompatibility((bool)$this->typoScriptRepository->getModelConfigurationByScope('FORM', 'compatibilityMode'));
                if (isset($this->typoScript['compatibilityMode'])) {
-                       $this->setCompatibility($this->typoScript['compatibilityMode']);
+                       if ((int)($this->typoScript['compatibilityMode']) === 0) {
+                               $this->setCompatibility(FALSE);
+                       } else {
+                               $this->setCompatibility(TRUE);
+                       }
                }
                // Set the theme name
                if (!empty($this->typoScript['themeName'])) {
index 0ceae9b..a0ea453 100755 (executable)
@@ -14,7 +14,7 @@ namespace TYPO3\CMS\Form\Domain\Validator;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Form\Domain\Model\Configuration;
+use TYPO3\CMS\Form\Utility\FormUtility;
 
 abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator {
 
@@ -26,29 +26,16 @@ abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator
        const LOCALISATION_OBJECT_NAME = 'tx_form_system_validate';
 
        /**
-        * @var \TYPO3\CMS\Form\Utility\FormUtility
+        * @var FormUtility
         */
        protected $formUtility;
 
        /**
-        * @var Configuration
-        */
-       protected $configuration;
-
-       /**
         * @var mixed
         */
        protected $rawArgument;
 
        /**
-        * @param \TYPO3\CMS\Form\Utility\FormUtility $formUtility
-        * @return void
-        */
-       public function injectFormUtility(\TYPO3\CMS\Form\Utility\FormUtility $formUtility) {
-               $this->formUtility = $formUtility;
-       }
-
-       /**
         * @var array
         */
        protected $supportedOptions = array(
@@ -65,17 +52,17 @@ abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator
        protected $acceptsEmptyValues = FALSE;
 
        /**
-        * @param Configuration $configuration
+        * @param mixed $rawArgument
         */
-       public function setConfiguration(Configuration $configuration) {
-               $this->configuration = $configuration;
+       public function setRawArgument($rawArgument) {
+               $this->rawArgument = $rawArgument;
        }
 
        /**
-        * @param mixed $rawArgument
+        * @param FormUtility $formUtility
         */
-       public function setRawArgument($rawArgument) {
-               $this->rawArgument = $rawArgument;
+       public function setFormUtility(FormUtility $formUtility) {
+               $this->formUtility = $formUtility;
        }
 
        /**
@@ -106,68 +93,18 @@ abstract class AbstractValidator extends \TYPO3\CMS\Extbase\Validation\Validator
         * Set the message, like 'required' for the validation rule
         * and substitutes markers for values, like %maximum
         *
-        * The output will be a rendered cObject if allowed.
-        * If cObject rendering is allowed:
-        * If no parameter is given, it will take the default locallang label
-        * If only first parameter, then it's supposed to be a TEXT cObj
-        * When both are filled, it's supposed to be a cObj made by the administrator
-        * In the last case, no markers will be substituted
-        * If cObject rendering is not allowed:
-        * If no parameter is given, it will take the default locallang label
-        * If the first parameter is given and its no array, then the markers
-        * are substituted.
-        * If the first parameter is given and its a array, then we try some fallbacks:
-        * If the array contains a value key, then return the value
-        * If the data array contains a data key, then try to localize it via
-        * extbase LocalizationUtility::translate
         *
-        * @param string|array $message Message as string or TS
-        * @param string $type Name of the cObj
+        * @param mixed $message Message as string or TS
+        * @param NULL|string $type Name of the cObj
         * @param string $messageType message or error
-        * @param \TYPO3\CMS\Extbase\Validation\Validator\AbstractValidator $validator
         * @return string
         */
-       public function renderMessage($message = '', $type = 'TEXT', $messageType = 'message') {
-               if ($this->configuration->getContentElementRendering()) {
-                       if (empty($message)) {
-                               if (!empty($type)) {
-                                               // cObj Text, cast to - message = "some message", type = "TEXT"
-                                       $message = $type;
-                                       $type = 'TEXT';
-                               } else {
-                                               // cObj Text, default locallang label
-                                       $type = 'TEXT';
-                                       $message = $this->getLocalLanguageLabel($messageType);
-                               }
-                               $value['value'] = $this->substituteMarkers($message);
-                       } elseif (!is_array($message)) {
-                                       // cObj Text, $message is string and replaced by the validator function
-                               $value['value'] = $this->substituteMarkers($message);
-                       } else {
-                                       // cObj $type, message is rendered as cOnj
-                               $value = $message;
-                       }
-                       $message = $this->formUtility->renderContentObject($type, $value);
-               } else {
-                       if (empty($message)) {
-                               if (!empty($type)) {
-                                       $message = $type;
-                               } else {
-                                       $message = $this->getLocalLanguageLabel($messageType);
-                               }
-                               $message = $this->substituteMarkers($message);
-                       } elseif (!is_array($message)) {
-                               $message = $this->substituteMarkers($message);
-                       } else {
-                               if (isset($message['value'])) {
-                                       $message = $message['value'];
-                               } elseif (isset($message['data'])) {
-                                       $message = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($message['data'], 'form');
-                               } else {
-                                       $message = '';
-                               }
-                       }
-               }
-               return $message;
+       public function renderMessage($message = NULL, $type = NULL, $messageType = 'message') {
+               $message = $this->formUtility->renderItem(
+                       $message,
+                       $type,
+                       $this->getLocalLanguageLabel($messageType)
+               );
+               return $this->substituteMarkers($message);
        }
 }
index 36a038f..d480bf6 100644 (file)
@@ -134,6 +134,9 @@ class HandleIncomingFormValues implements SingletonInterface {
                                        $element->setHtmlAttribute('selected', NULL);
                                }
                        }
+               } elseif ($element->getElementType() === 'TEXTAREA') {
+                       $incomingData = $formBuilder->getIncomingData()->getIncomingField($elementName);
+                       $element->setAdditionalArgument('text', $incomingData);
                } elseif ($element->getElementType() === 'FILEUPLOAD') {
                        if (
                                $formBuilder->getValidationErrors() == NULL
index f025571..dfdfe9f 100644 (file)
@@ -19,6 +19,7 @@ use TYPO3\CMS\Core\Utility\MailUtility;
 use TYPO3\CMS\Core\Utility\MathUtility;
 use TYPO3\CMS\Core\Mail\Rfc822AddressesParser;
 use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+use TYPO3\CMS\Form\Utility\FormUtility;
 
 /**
  * The mail post processor
@@ -43,6 +44,11 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
        protected $sessionUtility;
 
        /**
+        * @var FormUtility
+        */
+       protected $formUtility;
+
+       /**
         * @var \TYPO3\CMS\Form\Domain\Model\Element
         */
        protected $form;
@@ -109,6 +115,7 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @return string HTML message from this processor
         */
        public function process() {
+               $this->formUtility = FormUtility::create($this->controllerContext->getConfiguration());
                $this->setSubject();
                $this->setFrom();
                $this->setTo();
@@ -445,45 +452,11 @@ class MailPostProcessor extends AbstractPostProcessor implements PostProcessorIn
         * @return string
         */
        protected function renderMessage($messageType) {
-               $message = NULL;
-               $type = NULL;
-               if ($this->typoScript['messages.'][$messageType]) {
-                       $type = $this->typoScript['messages.'][$messageType];
-               }
-               if ($this->typoScript['messages.'][$messageType . '.']) {
-                       $message = $this->typoScript['messages.'][$messageType . '.'];
-               }
-               if ($this->controllerContext->getConfiguration()->getContentElementRendering()) {
-                       if (empty($message)) {
-                               if (!empty($type)) {
-                                       $message = $type;
-                                       $type = 'TEXT';
-                               } else {
-                                       $type = 'TEXT';
-                                       $message = $this->getLocalLanguageLabel($messageType);
-                               }
-                               $value['value'] = $message;
-                               $value['wrap'] = '<p>|</p>';
-                       } elseif (!is_array($message)) {
-                               $value['value'] = $message;
-                               $value['wrap'] = '<p>|</p>';
-                       } else {
-                               $value = $message;
-                       }
-                       $message = $GLOBALS['TSFE']->cObj->cObjGetSingle(
-                               $type,
-                               $value
-                       );
-               } else {
-                       if (isset($message['value'])) {
-                               $message = $message['value'];
-                       } elseif (isset($message['data'])) {
-                               $message = LocalizationUtility::translate($message['data'], 'form');
-                       } elseif ($type !== '') {
-                               $message = $this->getLocalLanguageLabel($messageType);
-                       }
-               }
-               return $message;
+               return $this->formUtility->renderItem(
+                       $this->typoScript['messages.'][$messageType . '.'],
+                       $this->typoScript['messages.'][$messageType],
+                       $this->getLocalLanguageLabel($messageType)
+               );
        }
 
        /**
index 7a63671..8a6c842 100644 (file)
@@ -499,35 +499,30 @@ class CompatibilityLayerUtility {
        }
 
        /**
-        * Remap some old inconsistent settings
+        * Get new name for some old inconsistent attribute names
         *
         * @param string $elementType
         * @param string $attributeName
-        * @param array $additionalArguments
-        * @param array $userConfiguredElementTyposcript The configuration array
-        * @return array
+        * @return string
         * @deprecated since TYPO3 CMS 7, this function will be removed in TYPO3 CMS 8, as the functionality is now done via fluid
         */
-       public function remapOldAttributes($elementType, $attributeName, array $additionalArguments, $userConfiguredElementTyposcript = array()) {
+       public function getNewAttributeName($elementType, $attributeName) {
                if ($elementType === 'OPTION') {
                        if ($attributeName === 'data') {
                                GeneralUtility::deprecationLog('EXT:form: Deprecated since TYPO3 CMS 7, use text instead of data to configure the OPTION text');
-                               $userConfiguredElementTyposcript['text'] = $userConfiguredElementTyposcript['data'];
-                               unset($userConfiguredElementTyposcript[$attributeName]);
                                $attributeName = 'text';
                        }
                } elseif ($elementType === 'TEXTAREA') {
                        if ($attributeName === 'data') {
                                GeneralUtility::deprecationLog('EXT:form: Deprecated since TYPO3 CMS 7, use text instead of data to configure the TEXTAREA value');
-                               $userConfiguredElementTyposcript['value'] = $userConfiguredElementTyposcript['data'];
-                               unset($userConfiguredElementTyposcript[$attributeName]);
-                               $attributeName = 'value';
+                               $attributeName = 'text';
+                       }
+               } elseif ($elementType === 'TEXTBLOCK') {
+                       if ($attributeName === 'content') {
+                               GeneralUtility::deprecationLog('EXT:form: Deprecated since TYPO3 CMS 7, use text instead of content to configure the TEXTBLOCK value');
+                               $attributeName = 'text';
                        }
                }
-               return array(
-                       'attributeName' => $attributeName,
-                       'additionalArguments' => $additionalArguments,
-                       'userConfiguredElementTyposcript' => $userConfiguredElementTyposcript,
-               );
+               return $attributeName;
        }
 }
index 50b29bd..f25ff75 100644 (file)
@@ -14,25 +14,183 @@ namespace TYPO3\CMS\Form\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Form\Domain\Model\Configuration;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
- * A session utility
+ * A utility for the form
  */
-class FormUtility implements \TYPO3\CMS\Core\SingletonInterface {
+class FormUtility {
 
        /**
-        * Render a content object if allowed
+        * @param Configuration $configuration
+        * @return FormBuilder
+        */
+       static public function create(Configuration $configuration) {
+               /** @var FormBuilder $formBuilder */
+               $formUtility = FormUtility::getObjectManager()->get(FormUtility::class);
+               $formUtility->setConfiguration($configuration);
+               return $formUtility;
+       }
+
+       /**
+        * @var Configuration
+        */
+       protected $configuration;
+
+       /**
+        * @param Configuration $configuration
+        */
+       public function setConfiguration(Configuration $configuration) {
+               $this->configuration = $configuration;
+       }
+
+       /**
+        * Render TypoScript values
+        * There are different variants. It is possible that the TypoScript
+        * which we want to render looks like this:
+        *
+        * array(
+        *   'message' => 'TEXT',
+        *   'message.' => array(
+        *     'value' => 'blah'
+        *   )
+        * )
+        *
+        * or in "short syntax" (the wizard writes some syntax partly)
+        *
+        * array(
+        *   'message.' => array(
+        *     'value' => 'blah'
+        *   )
+        * )
+        *
+        * or it is simply a string.
         *
-        * @param string $key
-        * @param array $configuration
+        * Furthermore we have 2 modes:
+        * - contentelement rendering is allowed
+        * - or contentelement rendering is not allowed
+        *
+        * This method will take care of all scenarios and provide some
+        * fallbacks.
+        * Call this method always in the following way:
+        *
+        * renderItem(
+        *   $typoscript['itemToRender.'],
+        *   $typoscript['itemToRender'],
+        *   $optionalDefaultMessage
+        * )
+        *
+        * You dont have to handle if is $typoscript['itemToRender.'] is
+        * set or not. This function determines this.
+        * This allows us to get the value of a TypoScript construct
+        * without knowing about "short syntax", only a string, a cObject,
+        * if cObject rendering is allowed and so on.
+        *
+        * If contentelement rendering is allowed:
+        *   If $type and $configuration are set
+        *   render as an cObject.
+        *
+        *   If $type is set but $configuration is empty
+        *   only return the value of $type.
+        *
+        *   If $type is empty and $configuration is an array ("short syntax")
+        *   render the $configuration as content type TEXT.
+        *
+        *   If $type is empty and $configuration is a string
+        *   render the value of $configuration like
+        *   10 = TEXT 10.value = $configuration.
+        *
+        *   If $type is empty and $configuration is empty
+        *   return the $defaultMessage.
+        *
+        * If contentelement rendering is not allowed:
+        *   If $type is set but $configuration is empty
+        *   only return the value of $type.
+        *
+        *   If $type is set and $configuration['value'] isset
+        *   return the value of $configuration['value'].
+        * 
+        *   If $type is set and $configuration['value'] is not set
+        *   return the value of $defaultMessage.
+        * 
+        *   If $type is empty and $configuration['value'] isset
+        *   return the value of $configuration['value'].
+        * 
+        *   If $type is empty and $configuration['value'] is not set
+        *   return the value of $defaultMessage.
+        *
+        * @param mixed $configuration a string or a TypoScript array
+        * @param NULL|string $type cObject type or simply a string value
+        * @param string $defaultMessage
         * @return string
         */
-       public function renderContentObject($key, array $configuration) {
-               return $GLOBALS['TSFE']->cObj->cObjGetSingle(
-                       $key,
-                       $configuration
-               );
+       public function renderItem($configuration, $type = NULL, $defaultMessage = '') {
+               if ($this->configuration->getContentElementRendering()) {
+                       $renderedMessage = NULL;
+                       if ($type !== NULL) {
+                               if (is_array($configuration)) {
+                                       /* Direct cObject rendering */
+                                       $value = $configuration;
+                               } else {
+                                       /* got only a string, no rendering required */
+                                       $renderedMessage = $type;
+                               }
+                       } else {
+                               if ($configuration !== NULL) {
+                                       /* Render the "short syntax"
+                                        * The wizard write things like label.value
+                                        * The previous version of EXT:form interpreted this
+                                        * as a TEXT content object, so we do the same
+                                        *  */
+                                       $type = 'TEXT';
+                                       if (is_array($configuration)) {
+                                               $value = $configuration;
+                                       } else {
+                                               $value['value'] = $configuration;
+                                       }
+                               } else {
+                                       /* return the default message
+                                        * If $type === NULL and $configuration === NULL
+                                        * return the default message (if set).
+                                        * */
+                                       $renderedMessage = $defaultMessage;
+                               }
+                       }
+                       if ($renderedMessage === NULL) {
+                               $renderedMessage = $GLOBALS['TSFE']->cObj->cObjGetSingle(
+                                       $type,
+                                       $value
+                               );
+                       }
+               } else {
+                       if ($type !== NULL) {
+                               if ($configuration !== NULL) {
+                                       /* the wizard write things like label.value = some text
+                                        * so we need the handle that, even content object rendering
+                                        * is not allowed.
+                                        *  */
+                                       if (isset($configuration['value'])) {
+                                               $renderedMessage = $configuration['value'];
+                                       } else {
+                                               $renderedMessage = $defaultMessage;
+                                       }
+                               } else {
+                                       // string, no rendering required
+                                       $renderedMessage = $type;
+                               }
+                       } else {
+                               $renderedMessage = $defaultMessage;
+                               if (
+                                       is_array($configuration)
+                                       && isset($configuration['value'])
+                               ) {
+                                       $renderedMessage = $configuration['value'];
+                               }
+                       }
+               }
+               return $renderedMessage;
        }
 
        /**
index 3c8b96d..79538ca 100644 (file)
@@ -177,7 +177,7 @@ lib.tx_form.registeredElements.defaultModelDescription {
                # viewhelpers where we need some typecasting.
        viewHelperDefaulArguments =
 
-               # childsInerhitName
+               # childrenInheritName
                # Used by: frontend
                # Overwriteable by user: FALSE
                #
@@ -185,7 +185,7 @@ lib.tx_form.registeredElements.defaultModelDescription {
                # the parent element
                #
                # toDo: description
-       childsInerhitName = 0
+       childrenInheritName = 0
 
                # visibleInShowAction
                # Used by: frontend
@@ -1329,7 +1329,7 @@ plugin.tx_form {
                        CHECKBOXGROUP {
                                partialPath =< plugin.tx_form.view.elementPartials.CHECKBOXGROUP.10.partialPath
 
-                               childsInerhitName = 1
+                               childrenInheritName = 1
 
                                visibleInConfirmationAction = 1
                                visibleInMail = 1
@@ -1345,7 +1345,7 @@ plugin.tx_form {
                        RADIOGROUP {
                                partialPath =< plugin.tx_form.view.elementPartials.RADIOGROUP.10.partialPath
 
-                               childsInerhitName = 1
+                               childrenInheritName = 1
 
                                visibleInConfirmationAction = 1
                                visibleInMail = 1
index 4c4bab2..b7bda7c 100644 (file)
@@ -1,6 +1,6 @@
 <f:if condition="{model.showElement}">
        <f:format.raw>{model.layout.elementOuterWrap.0}</f:format.raw>
-       {model.additionalArguments.value}
+       {model.additionalArguments.text}
        <f:format.raw>{model.layout.elementOuterWrap.1}</f:format.raw>
 </f:if>
 
@@ -16,7 +16,7 @@
        onclick="{model.additionalArguments.onclick}"
 
        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
-       value="{model.additionalArguments.value}"
+       value="{model.additionalArguments.text}"
 
        additionalAttributes="{model.htmlAttributes}"
 />
index 9a68a68..5ac6424 100644 (file)
@@ -3,6 +3,6 @@
   <td style="width: 200px;" valign="top">
     <em>{model.additionalArguments.label}</em>
   </td>
-  <td>{model.additionalArguments.value}</td>
+  <td>{model.additionalArguments.text}</td>
 </tr>
 </f:if>
\ No newline at end of file
index 89d4c30..5c6ea67 100644 (file)
@@ -1 +1 @@
-{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" content="{model.additionalArguments.value}" newLineAfterLabel="1" indent="4" /><form:plainMail indent="-4" /></f:if>
+{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" content="{model.additionalArguments.text}" newLineAfterLabel="1" indent="4" /><form:plainMail indent="-4" /></f:if>
index d23419b..dbf9c3e 100644 (file)
@@ -12,7 +12,7 @@
                        onclick="{model.additionalArguments.onclick}"
 
                        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
-                       value="{model.additionalArguments.value}"
+                       value="{model.additionalArguments.text}"
 
                        autofocus="{model.additionalArguments.autofocus}"
                        rows="{model.additionalArguments.rows}"
index db3847b..5171a9e 100644 (file)
@@ -1,3 +1,3 @@
 <f:if condition="{model.showElement}">
-       <f:format.raw>{model.additionalArguments.value}</f:format.raw>
+       <f:format.raw>{model.additionalArguments.text}</f:format.raw>
 </f:if>
\ No newline at end of file
index 138acc4..59fb6c3 100644 (file)
@@ -1,7 +1,7 @@
 <f:if condition="{model.showElement}">
        <li class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
                <label>{model.additionalArguments.label}</label>
-               {model.additionalArguments.value}
+               {model.additionalArguments.text}
        </li>
 </f:if>
 
@@ -17,7 +17,7 @@
        onclick="{model.additionalArguments.onclick}"
 
        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
-       value="{model.additionalArguments.value}"
+       value="{model.additionalArguments.text}"
 
        additionalAttributes="{model.htmlAttributes}"
 />
index 9a68a68..5ac6424 100644 (file)
@@ -3,6 +3,6 @@
   <td style="width: 200px;" valign="top">
     <em>{model.additionalArguments.label}</em>
   </td>
-  <td>{model.additionalArguments.value}</td>
+  <td>{model.additionalArguments.text}</td>
 </tr>
 </f:if>
\ No newline at end of file
index 89d4c30..5c6ea67 100644 (file)
@@ -1 +1 @@
-{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" content="{model.additionalArguments.value}" newLineAfterLabel="1" indent="4" /><form:plainMail indent="-4" /></f:if>
+{namespace form=TYPO3\CMS\Form\ViewHelpers}<f:if condition="{model.showElement}"><form:plainMail labelContent="{model}" content="{model.additionalArguments.text}" newLineAfterLabel="1" indent="4" /><form:plainMail indent="-4" /></f:if>
index c57b55e..30d704a 100644 (file)
@@ -22,7 +22,7 @@
                        onclick="{model.additionalArguments.onclick}"
 
                        name="{model.additionalArguments.prefix}[{model.additionalArguments.name}]"
-                       value="{model.additionalArguments.value}"
+                       value="{model.additionalArguments.text}"
 
                        autofocus="{model.additionalArguments.autofocus}"
                        rows="{model.additionalArguments.rows}"
index fe15e4f..625809e 100644 (file)
@@ -1,5 +1,5 @@
 <f:if condition="{model.showElement}">
        <li class="csc-form-{model.elementCounter} csc-form-element csc-form-element-{model.elementTypeLowerCase}">
-               <f:format.raw>{model.additionalArguments.value}</f:format.raw>
+               <f:format.raw>{model.additionalArguments.text}</f:format.raw>
        </li>
 </f:if>
\ No newline at end of file