[BUGFIX] Make ext:form work with namespaced classnames
authorThomas Maroschik <tmaroschik@dfau.de>
Tue, 28 Aug 2012 23:47:33 +0000 (01:47 +0200)
committerJigal van Hemert <jigal@xs4all.nl>
Tue, 11 Sep 2012 18:38:53 +0000 (20:38 +0200)
Change-Id: I26b501e49d41656eb50996be4d56b4c18f1563ba
Fixes: #40364
Related: #40095
Releases: 6.0
Reviewed-on: http://review.typo3.org/14178
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
Reviewed-by: Jigal van Hemert
Tested-by: Jigal van Hemert
19 files changed:
typo3/sysext/form/Classes/Controller/FormController.php
typo3/sysext/form/Classes/Domain/Factory/TypoScriptFactory.php
typo3/sysext/form/Classes/Domain/Model/Additional/AdditionalAdditionalElement.php
typo3/sysext/form/Classes/Domain/Model/Attribute/AttributesAttribute.php
typo3/sysext/form/Classes/Domain/Repository/ContentRepository.php
typo3/sysext/form/Classes/PostProcess/MailPostProcessor.php
typo3/sysext/form/Classes/PostProcess/PostProcessor.php
typo3/sysext/form/Classes/Utility/FilterUtility.php
typo3/sysext/form/Classes/Utility/FormUtility.php
typo3/sysext/form/Classes/Utility/TypoScriptToJsonConverter.php
typo3/sysext/form/Classes/Utility/ValidatorUtility.php
typo3/sysext/form/Classes/View/Confirmation/Element/AbstractElementView.php
typo3/sysext/form/Classes/View/Confirmation/Element/ContainerElementView.php
typo3/sysext/form/Classes/View/Form/Element/AbstractElementView.php
typo3/sysext/form/Classes/View/Form/Element/ContainerElementView.php
typo3/sysext/form/Classes/View/Mail/Html/Element/AbstractElementView.php
typo3/sysext/form/Classes/View/Mail/Html/Element/ContainerElementView.php
typo3/sysext/form/Classes/View/Mail/Plain/Element/ContainerElementView.php
typo3/sysext/form/Tests/Unit/PostProcess/PostProcessorTest.php

index c02d5f7..435f1d8 100644 (file)
@@ -98,8 +98,8 @@ class FormController {
                if ($typoScriptObjectName === 'FORM') {
                        if ($contentObject->data['CType'] === 'mailform') {
                                $bodytext = $contentObject->data['bodytext'];
-                               /** @var $typoScriptParser t3lib_tsparser */
-                               $typoScriptParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('t3lib_tsparser');
+                               /** @var $typoScriptParser \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser */
+                               $typoScriptParser = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\TypoScript\\Parser\\TypoScriptParser');
                                $typoScriptParser->parse($bodytext);
                                $mergedTypoScript = \TYPO3\CMS\Core\Utility\GeneralUtility::array_merge_recursive_overrule((array) $typoScriptParser->setup, (array) $typoScript);
                                // Disables content elements since TypoScript is handled that could contain insecure settings:
index 2324056..6171692 100644 (file)
@@ -163,9 +163,9 @@ class TypoScriptFactory implements \TYPO3\CMS\Core\SingletonInterface {
        public function createElement($class, array $arguments = array()) {
                $class = strtolower((string) $class);
                if ($class === 'form') {
-                       $className = 'tx_form_Domain_Model_' . ucfirst($class);
+                       $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\' . ucfirst($class);
                } else {
-                       $className = 'tx_form_Domain_Model_Element_' . ucfirst($class);
+                       $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Element\\' . ucfirst($class) . 'Element';
                }
                /** @var $object \TYPO3\CMS\Form\Domain\Model\Element\AbstractElement */
                $object = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
@@ -371,4 +371,4 @@ class TypoScriptFactory implements \TYPO3\CMS\Core\SingletonInterface {
 }
 
 
-?>
\ No newline at end of file
+?>
index da07fbe..07df56e 100644 (file)
@@ -49,7 +49,7 @@ class AdditionalAdditionalElement {
         */
        public function addAdditional($class, $type, $value) {
                $class = strtolower((string) $class);
-               $className = 'tx_form_Domain_Model_Additional_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Additional\\' . ucfirst($class) . 'AdditionalElement';
                $this->additional[$class] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $type, $value);
                return $this;
        }
index 0dd75a5..a5b0b87 100644 (file)
@@ -75,7 +75,7 @@ class AttributesAttribute {
         */
        public function addAttribute($class, $value) {
                $class = strtolower((string) $class);
-               $className = 'tx_form_Domain_Model_Attributes_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\Domain\\Model\\Attribute\\' . ucfirst($class) . 'Attribute';
                $this->attributes[$class] = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $value, $this->elementId);
                return $this;
        }
index 4703fe2..69ca58c 100644 (file)
@@ -108,7 +108,7 @@ class ContentRepository {
                if ($record) {
                        $typoscript = $record->getTyposcript();
                        /** @var $converter \TYPO3\CMS\Form\Utility\TypoScriptToJsonConverter */
-                       $converter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Domain\\Factory\\TypoScriptFactoryToJson');
+                       $converter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Utility\\TypoScriptToJsonConverter');
                        $json = $converter->convert($typoscript);
                }
                return $json;
index c25d323..5edf988 100644 (file)
@@ -246,7 +246,7 @@ class MailPostProcessor implements \TYPO3\CMS\Form\PostProcess\PostProcessorInte
         */
        protected function setPlainContent() {
                /** @var $view \TYPO3\CMS\Form\View\Mail\Plain\PlainView */
-               $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Mail\\MailView_Plain', $this->form);
+               $view = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\View\\Mail\\Plain\\PlainView', $this->form);
                $plainContent = $view->render();
                $this->mailMessage->addPart($plainContent, 'text/plain');
        }
index c962b27..287a69a 100644 (file)
@@ -67,7 +67,7 @@ class PostProcessor {
                                if (class_exists($this->typoScript[$key], TRUE)) {
                                        $className = $this->typoScript[$key];
                                } else {
-                                       $classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\PostProcessor_' . ucfirst(strtolower($this->typoScript[$key]));
+                                       $classNameExpanded = 'TYPO3\\CMS\\Form\\PostProcess\\' . ucfirst(strtolower($this->typoScript[$key])) . 'PostProcessor';
                                        if (class_exists($classNameExpanded, TRUE)) {
                                                $className = $classNameExpanded;
                                        }
index 690e8a7..1b90657 100644 (file)
@@ -111,7 +111,7 @@ class FilterUtility implements \TYPO3\CMS\Form\Filter\FilterInterface {
         */
        static public function createFilter($class, array $arguments = NULL) {
                $class = strtolower((string) $class);
-               $className = 'TYPO3\\CMS\\Form\\Utility\\FilterUtility_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\Filter\\' . ucfirst($class) . 'Filter';
                if (is_null($arguments)) {
                        $filter = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
                } else {
index d554b57..98c5583 100644 (file)
@@ -129,7 +129,7 @@ class FormUtility implements \TYPO3\CMS\Core\SingletonInterface {
         * @return string
         */
        public function getLastPartOfClassName($object, $lowercase = FALSE) {
-               $lastPart = preg_replace('/.*_([^_]*)$/', '${1}', get_class($object), 1);
+               $lastPart = preg_replace('/^.*\\\\([^\\\\]+?)(Additional|Attribute|Json|Element|View)+$/', '${1}', get_class($object), 1);
                if ($lowercase) {
                        $lastPart = strtolower($lastPart);
                }
index dbd0b4a..cdab194 100644 (file)
@@ -61,7 +61,7 @@ class TypoScriptToJsonConverter {
         */
        public function createElement($class, array $arguments = array()) {
                $class = strtolower((string) $class);
-               $className = 'tx_form_Domain_Model_Json_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\Domain\\Model\Json\\' . ucfirst($class) . 'JsonElement';
                $this->addValidationRules($arguments);
                /** @var $object \TYPO3\CMS\Form\Domain\Model\Json\AbstractJsonElement */
                $object = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className);
index f88a84b..335cc15 100644 (file)
@@ -82,7 +82,7 @@ class ValidatorUtility implements \TYPO3\CMS\Core\SingletonInterface {
         */
        public function createRule($class, $arguments = array()) {
                $class = strtolower((string) $class);
-               $className = 'TYPO3\\CMS\\Form\\Utility\\ValidatorUtility_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\Validation\\' . ucfirst($class) . 'Validator';
                $rule = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $arguments);
                return $rule;
        }
index 1ce5dbc..d03626d 100644 (file)
@@ -108,7 +108,7 @@ abstract class AbstractElementView {
                                        }
                                        break;
                                case 'label':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label'));
                                                }
@@ -120,7 +120,7 @@ abstract class AbstractElementView {
                                        }
                                        break;
                                case 'legend':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend'));
                                                }
@@ -293,7 +293,7 @@ abstract class AbstractElementView {
         */
        protected function createAdditional($class) {
                $class = strtolower((string) $class);
-               $className = 'TYPO3\\CMS\\Form\\View\\Confirmation\\Additional\\AdditionalElementView_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Confirmation\\Additional\\' . ucfirst($class) . 'AdditionalElementView';
                return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->model);
        }
 
index a652036..b4ef888 100644 (file)
@@ -85,7 +85,7 @@ class ContainerElementView extends \TYPO3\CMS\Form\View\Confirmation\Element\Abs
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;
                $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
-               $className = 'TYPO3\\CMS\\Form\\View\\Confirmation\\ConfirmationView_Element_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Confirmation\\Element\\' . ucfirst($class) . 'ElementView';
                if (class_exists($className)) {
                        $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
                }
index 92e80ef..a559228 100644 (file)
@@ -95,7 +95,7 @@ abstract class AbstractElementView {
        protected function getExpectedModelName(\TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $model) {
                if (!isset($this->expectedModelName)) {
                        $specificName = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($this);
-                       $this->expectedModelName = 'tx_form_Domain_Model_Element_' . $specificName;
+                       $this->expectedModelName = 'TYPO3\\CMS\\Form\\Domain\\Model\\Element\\' . $specificName . 'Element';
                }
                return $this->expectedModelName;
        }
@@ -143,7 +143,7 @@ abstract class AbstractElementView {
                                        $this->setAttributes($node);
                                        break;
                                case 'label':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label'));
                                                }
@@ -157,7 +157,7 @@ abstract class AbstractElementView {
                                        }
                                        break;
                                case 'legend':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend'));
                                                }
@@ -248,27 +248,27 @@ abstract class AbstractElementView {
                /** @var $layoutHandler \TYPO3\CMS\Form\Layout */
                $layoutHandler = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Form\\Layout');
                switch ($type) {
-               case 'element':
-                       $layoutDefault = $this->layout;
-                       $objectClass = get_class($this);
-                       $type = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($this, TRUE);
-                       if (strstr($objectClass, '_Additional_')) {
-                               $additionalModel = $this->model->getAdditionalObjectByKey($type);
-                               $layoutOverride = $additionalModel->getLayout();
-                       } else {
-                               $layoutOverride = $this->model->getLayout();
-                       }
-                       $layout = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
-                       break;
-               case 'elementWrap':
-                       $layoutDefault = $this->elementWrap;
-                       $elementWrap = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
-                       $layout = str_replace('<element />', $this->getLayout('element'), $elementWrap);
-                       break;
-               case 'containerWrap':
-                       $layoutDefault = $this->containerWrap;
-                       $layout = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
-                       break;
+                       case 'element':
+                               $layoutDefault = $this->layout;
+                               $objectClass = get_class($this);
+                               $type = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($this, TRUE);
+                               if (strrchr($objectClass, 'AdditionalElement')) {
+                                       $additionalModel = $this->model->getAdditionalObjectByKey($type);
+                                       $layoutOverride = $additionalModel->getLayout();
+                               } else {
+                                       $layoutOverride = $this->model->getLayout();
+                               }
+                               $layout = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
+                               break;
+                       case 'elementWrap':
+                               $layoutDefault = $this->elementWrap;
+                               $elementWrap = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
+                               $layout = str_replace('<element />', $this->getLayout('element'), $elementWrap);
+                               break;
+                       case 'containerWrap':
+                               $layoutDefault = $this->containerWrap;
+                               $layout = $layoutHandler->getLayoutByObject($type, $layoutDefault, $layoutOverride);
+                               break;
                }
                return $layout;
        }
@@ -345,7 +345,7 @@ abstract class AbstractElementView {
         */
        protected function createAdditional($class) {
                $class = strtolower((string) $class);
-               $className = 'TYPO3\\CMS\\Form\\View\\Form\\Additional\\AdditionalElementView_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Form\\Additional\\' . ucfirst($class) . 'AdditionalElementView';
                return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->model);
        }
 
index 0f7dee7..e02b5be 100644 (file)
@@ -76,7 +76,7 @@ class ContainerElementView extends \TYPO3\CMS\Form\View\Form\Element\AbstractEle
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;
                $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
-               $className = 'TYPO3\\CMS\\Form\\View\\Form\\FormView_Element_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Form\\Element\\' . ucfirst($class) . 'ElementView';
                if (class_exists($className)) {
                        $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
                }
index b66a498..1c0328e 100644 (file)
@@ -108,7 +108,7 @@ abstract class AbstractElementView {
                                        }
                                        break;
                                case 'label':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('label'));
                                                } else {
@@ -119,7 +119,7 @@ abstract class AbstractElementView {
                                        $deleteNode = TRUE;
                                        break;
                                case 'legend':
-                                       if (!strstr(get_class($this), '_Additional_')) {
+                                       if (!strrchr(get_class($this), 'AdditionalElement')) {
                                                if ($this->model->additionalIsSet($nodeName)) {
                                                        $this->replaceNodeWithFragment($dom, $node, $this->getAdditional('legend'));
                                                }
@@ -290,7 +290,7 @@ abstract class AbstractElementView {
         */
        protected function createAdditional($class) {
                $class = strtolower((string) $class);
-               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Html\\Additional\\AdditionalElementView_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Html\\Additional\\' . ucfirst($class) . 'AdditionalElementView';
                return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $this->model);
        }
 
index 0d56ded..580f2a4 100644 (file)
@@ -85,7 +85,7 @@ class ContainerElementView extends \TYPO3\CMS\Form\View\Mail\Html\Element\Abstra
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;
                $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
-               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Html\\HtmlView_Element_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Html\\Element\\' . ucfirst($class) . 'ElementView';
                if (class_exists($className)) {
                        $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild);
                }
index 7422d81..e53d478 100644 (file)
@@ -54,7 +54,7 @@ class ContainerElementView extends \TYPO3\CMS\Form\View\Mail\Plain\Element\Abstr
        protected function renderChild(\TYPO3\CMS\Form\Domain\Model\Element\AbstractElement $modelChild, $spaces) {
                $content = '';
                $class = \TYPO3\CMS\Form\Utility\FormUtility::getInstance()->getLastPartOfClassName($modelChild);
-               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\MailView_Plain_Element_' . ucfirst($class);
+               $className = 'TYPO3\\CMS\\Form\\View\\Mail\\Plain\\Element\\' . ucfirst($class) . 'ElementView';
                if (class_exists($className)) {
                        /** @var $childElement \TYPO3\CMS\Form\View\Mail\Plain\Element\AbstractElementView */
                        $childElement = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($className, $modelChild, $spaces);
index 88c0032..5100589 100644 (file)
@@ -34,7 +34,7 @@ namespace TYPO3\CMS\Form\Tests\Unit\PostProcess;
 class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
 
        /**
-        * @var PHPUnit_Framework_MockObject_MockObject
+        * @var \PHPUnit_Framework_MockObject_MockObject
         */
        public $postprocessor;
 
@@ -63,34 +63,36 @@ class PostProcessorTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
         */
        public function setUp() {
                $this->form = new \TYPO3\CMS\Form\Domain\Model\Form();
-               $this->postprocessor = $this->getMock('TYPO3\\CMS\\Form\\PostProcess\\PostProcessor', array('sortTypoScriptKeyList'), array(
+               $this->postprocessor = $this->getMock('TYPO3\CMS\Form\PostProcess\PostProcessor', array('sortTypoScriptKeyList'), array(
                        $this->form,
                        array()
                ));
                $this->classNameWithoutPrefix = uniqid('postprocess');
                $this->classNameWithPrefix = uniqid('postprocess');
                $this->classNameWithoutInterface = uniqid('postprocess');
-               eval(((((((('class ' . $this->classNameWithoutPrefix) . ' implements TYPO3\\CMS\\Form\\PostProcess\\PostProcessor_Interface {
+               eval('
+                       namespace TYPO3\CMS\Form\PostProcess;
+                       class ' . $this->classNameWithoutPrefix . 'PostProcessor implements PostProcessorInterface {
 
-                               public function __construct(TYPO3\\CMS\\Form\\Domain\\Model\\Form $form, array $typoScript) {
+                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
 
                                }
 
                                public function process() {
                                        return \'processedWithoutPrefix\';
                                }
-                       }') . 'class TYPO3\\CMS\\Form\\PostProcess\\PostProcessor_') . $this->classNameWithPrefix) . ' implements TYPO3\\CMS\\Form\\PostProcess\\PostProcessor_Interface {
+                       }' . 'class ' . $this->classNameWithPrefix . 'PostProcessor implements PostProcessorInterface {
 
-                               public function __construct(TYPO3\\CMS\\Form\\Domain\\Model\\Form $form, array $typoScript) {
+                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
 
                                }
 
                                public function process() {
                                        return \'processedWithPrefix\';
                                }
-                       }') . 'class ') . $this->classNameWithoutInterface) . '{
+                       }' . 'class ' . $this->classNameWithoutInterface . 'PostProcessor{
 
-                               public function __construct(TYPO3\\CMS\\Form\\Domain\\Model\\Form $form, array $typoScript) {
+                               public function __construct(\TYPO3\CMS\Form\Domain\Model\Form $form, array $typoScript) {
 
                                }