[BUGFIX] Wrong content element rendering in system extension form
authorOliver Hader <oliver@typo3.org>
Tue, 20 Sep 2011 11:53:23 +0000 (13:53 +0200)
committerOliver Hader <oliver@typo3.org>
Tue, 20 Sep 2011 11:56:07 +0000 (13:56 +0200)
The ability to render custom content elements in the system extension form fails.

Change-Id: Ib2ff3cc391705be458140c9a0dea0e6255948e83
Resolves: #30088
Releases: 4.6
Reviewed-on: http://review.typo3.org/5117
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/form/Classes/Controller/Form.php
typo3/sysext/form/Classes/Domain/Factory/Typoscript.php
typo3/sysext/form/Classes/View/Form/Element/Abstract.php

index de4aaac..4f4a95c 100644 (file)
@@ -116,8 +116,10 @@ class tx_form_Controller_Form {
                                        (array) $typoscript
                                );
                        }
-                       $newTyposcript['10'] = 'FORM_INT';
-                       $newTyposcript['10.'] = $typoscript;
+                       $newTyposcript = array(
+                               '10' => 'FORM_INT',
+                               '10.' => $typoscript,
+                       );
                        $content = $contentObject->COBJ_ARRAY($newTyposcript, 'INT');
                } elseif ($typoscriptObjectName == 'FORM_INT') {
                        $this->initialize($typoscript);
index 6f7f7f7..64b5dcf 100644 (file)
@@ -101,8 +101,10 @@ class tx_form_Domain_Factory_Typoscript implements t3lib_Singleton {
                                $arguments = $this->getLocalConentObject()->joinTSarrays($arguments, $oldArguments);
                        }
                        $GLOBALS['TT']->incStackPointer();
-                       $contentObject['cObj'] = $class;
-                       $contentObject['cObj.'] = $arguments;
+                       $contentObject = array(
+                               'cObj' => $class,
+                               'cObj.' => $arguments,
+                       );
                        $this->addElement($parentElement, 'content', $contentObject);
                        $GLOBALS['TT']->decStackPointer();
                } elseif (in_array($class, tx_form_Common::getInstance()->getFormObjects())) {
@@ -112,8 +114,10 @@ class tx_form_Domain_Factory_Typoscript implements t3lib_Singleton {
                                throw $exception;
                        }
                } else {
-                       $contentObject['cObj'] = $class;
-                       $contentObject['cObj.'] = $arguments;
+                       $contentObject = array(
+                               'cObj' => $class,
+                               'cObj.' => $arguments,
+                       );
                        $this->addElement($parentElement, 'content', $contentObject);
                }
        }
@@ -151,27 +155,40 @@ class tx_form_Domain_Factory_Typoscript implements t3lib_Singleton {
                /** @var $object tx_form_Domain_Model_Element_Abstract */
                $object = t3lib_div::makeInstance($className);
 
-               $this->setAttributes($object, $arguments);
-               $this->setAdditionals($object, $arguments);
-               $this->setFilters($object, $arguments['filters.']);
-
-               $object->setLayout($arguments['layout']);
-               $object->setValue($arguments['value']);
-               $object->setName($arguments['name']);
-
                if ($class === 'content') {
                        $object->setData($arguments['cObj'], $arguments['cObj.']);
                } else {
                        $object->setData($arguments['data']);
+                       $this->reconstituteElement($object, $arguments);
                }
 
-               $object->setMessagesFromValidation();
-               $object->setErrorsFromValidation();
-               $object->checkFilterAndSetIncomingDataFromRequest();
+               return $object;
+       }
 
-               $this->getChildElementsByIntegerKey($object, $arguments);
+       /**
+        * Reconstitutes the domain model of the accordant element.
+        *
+        * @param tx_form_Domain_Model_Element_Abstract $element
+        * @param array $arguments Configuration array
+        * @return void
+        */
+       protected function reconstituteElement(tx_form_Domain_Model_Element_Abstract $element, array $arguments = array()) {
+               $this->setAttributes($element, $arguments);
+               $this->setAdditionals($element, $arguments);
 
-               return $object;
+               if (isset($arguments['filters.'])) {
+                       $this->setFilters($element, $arguments['filters.']);
+               }
+
+               $element->setLayout($arguments['layout']);
+               $element->setValue($arguments['value']);
+               $element->setName($arguments['name']);
+
+               $element->setMessagesFromValidation();
+               $element->setErrorsFromValidation();
+               $element->checkFilterAndSetIncomingDataFromRequest();
+
+               $this->getChildElementsByIntegerKey($element, $arguments);
        }
 
        /**
@@ -258,16 +275,14 @@ class tx_form_Domain_Factory_Typoscript implements t3lib_Singleton {
         * @param array $arguments TypoScript
         * @return void
         */
-       protected function setFilters(tx_form_Domain_Model_Element_Abstract $element, $arguments) {
-               if (is_array($arguments)) {
-                       $keys = t3lib_TStemplate::sortedKeyList($arguments);
-                       foreach ($keys as $key) {
-                               $class = $arguments[$key];
-                               if (intval($key) && !strstr($key, '.')) {
-                                       $filterArguments = $arguments[$key . '.'];
-                                       $filter = $element->makeFilter($class, $filterArguments);
-                                       $element->addFilter($filter);
-                               }
+       protected function setFilters(tx_form_Domain_Model_Element_Abstract $element, array $arguments) {
+               $keys = t3lib_TStemplate::sortedKeyList($arguments);
+               foreach ($keys as $key) {
+                       $class = $arguments[$key];
+                       if (intval($key) && !strstr($key, '.')) {
+                               $filterArguments = $arguments[$key . '.'];
+                               $filter = $element->makeFilter($class, $filterArguments);
+                               $element->addFilter($filter);
                        }
                }
        }
index 26b25a5..fe05164 100644 (file)
@@ -149,7 +149,7 @@ abstract class tx_form_View_Form_Element_Abstract {
                                                        $deleteNode = TRUE;
                                                        break;
                                                case 'content':
-                                                       $replaceNode = $dom->createTextNode($this->getElementData());
+                                                       $replaceNode = $dom->createTextNode($this->getElementData(FALSE));
                                                        $node->parentNode->insertBefore($replaceNode, $node);
                                                        $deleteNode = TRUE;
                                                        break;
@@ -334,10 +334,17 @@ abstract class tx_form_View_Form_Element_Abstract {
         * like <option>content</option>
         * or <textarea>content</textarea>
         *
+        * @param boolean $encodeSpecialCharacters Whether to encode the data
         * @return string
         */
-       public function getElementData() {
-               return htmlspecialchars($this->model->getData(), ENT_QUOTES);
+       public function getElementData($encodeSpecialCharacters = TRUE) {
+               $elementData = $this->model->getData();
+
+               if ($encodeSpecialCharacters) {
+                       $elementData = htmlspecialchars($elementData, ENT_QUOTES);
+               }
+
+               return $elementData;
        }
 
        /**