[BUGFIX] Form: Add more more semantic classes for elements
authorOliver Hader <oliver@typo3.org>
Thu, 3 Nov 2011 20:35:30 +0000 (21:35 +0100)
committerOliver Hader <oliver@typo3.org>
Tue, 29 Nov 2011 15:28:45 +0000 (16:28 +0100)
The system extension form renders elements with a wrapped class like
"csc-form-1" which just states the order or elements. To enable more
specific styling, a schema like the following is integrated:

csc-form-<id> csc-form-element csc-form-element-<type>

Change-Id: I0c03d047a757e8865f99b6200cc01bad19d06605
Fixes: #31561
Releases: 4.6, 4.7
Reviewed-on: http://review.typo3.org/6531
Reviewed-by: Georg Ringer
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/form/Classes/View/Confirmation/Element/Abstract.php
typo3/sysext/form/Classes/View/Confirmation/Element/Container.php
typo3/sysext/form/Classes/View/Form/Element/Abstract.php
typo3/sysext/form/Classes/View/Form/Element/Container.php
typo3/sysext/form/Classes/View/Mail/Html/Element/Abstract.php
typo3/sysext/form/Classes/View/Mail/Html/Element/Container.php

index adb448e..79ec49b 100644 (file)
@@ -34,7 +34,7 @@ abstract class tx_form_View_Confirmation_Element_Abstract {
        /**
         * The model for the current object
         *
-        * @var object
+        * @var tx_form_Domain_Model_Element_Abstract
         */
        protected $model;
 
@@ -360,6 +360,35 @@ abstract class tx_form_View_Confirmation_Element_Abstract {
        }
 
        /**
+        * Returns the type for the element wraps,
+        * like <li class="csc-form-element csc-form-element-abstract">...</li>
+        *
+        * @return string
+        */
+       public function getElementWrapType() {
+               $elementType = strtolower(
+                       tx_form_Common::getInstance()->getLastPartOfClassName($this->model)
+               );
+               $wrapType = 'csc-form-element csc-form-element-' . $elementType;
+
+               return $wrapType;
+       }
+
+       /**
+        * Returns all element wraps.
+        *
+        * @return string
+        */
+       public function getElementWraps() {
+               $wraps = array(
+                       $this->getElementWrapId(),
+                       $this->getElementWrapType(),
+               );
+
+               return implode(' ', $wraps);
+       }
+
+       /**
         * Read the noWrap value of an element
         * if TRUE the element does not need a element wrap
         * like <li>element</li>
index f6b3586..9973d8e 100644 (file)
@@ -71,7 +71,7 @@ class tx_form_View_Confirmation_Element_Container extends tx_form_View_Confirmat
                                } else {
                                        $childNode = $child->render('elementWrap');
                                        if ($childNode) {
-                                               $childNode->setAttribute('class', $child->getElementWrapId());
+                                               $childNode->setAttribute('class', $child->getElementWraps());
                                        }
                                }
                                if ($childNode) {
@@ -90,7 +90,7 @@ class tx_form_View_Confirmation_Element_Container extends tx_form_View_Confirmat
         * Create child object from the classname of the model
         *
         * @param object $modelChild The childs model
-        * @return object
+        * @return tx_form_View_Confirmation_Element_Abstract
         */
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;
index 6ae3ea3..c0e8fc6 100644 (file)
@@ -397,6 +397,35 @@ abstract class tx_form_View_Form_Element_Abstract {
        }
 
        /**
+        * Returns the type for the element wraps,
+        * like <li class="csc-form-element csc-form-element-abstract">...</li>
+        *
+        * @return string
+        */
+       public function getElementWrapType() {
+               $elementType = strtolower(
+                       tx_form_Common::getInstance()->getLastPartOfClassName($this)
+               );
+               $wrapType = 'csc-form-element csc-form-element-' . $elementType;
+
+               return $wrapType;
+       }
+
+       /**
+        * Returns all element wraps.
+        *
+        * @return string
+        */
+       public function getElementWraps() {
+               $wraps = array(
+                       $this->getElementWrapId(),
+                       $this->getElementWrapType(),
+               );
+
+               return implode(' ', $wraps);
+       }
+
+       /**
         * Read the noWrap value of an element
         * if TRUE the element does not need a element wrap
         * like <li>element</li>
index 2fdf546..3240828 100644 (file)
@@ -57,7 +57,7 @@ class tx_form_View_Form_Element_Container extends tx_form_View_Form_Element_Abst
                                $childNode = $child->render();
                        } else {
                                $childNode = $child->render('elementWrap');
-                               $childNode->setAttribute('class', $child->getElementWrapId());
+                               $childNode->setAttribute('class', $child->getElementWraps());
                        }
                        $importedNode = $dom->importNode($childNode, TRUE);
                        $documentFragment->appendChild($importedNode);
@@ -69,7 +69,7 @@ class tx_form_View_Form_Element_Container extends tx_form_View_Form_Element_Abst
         * Create child object from the classname of the model
         *
         * @param object $modelChild The childs model
-        * @return object
+        * @return tx_form_View_Form_Element_Abstract
         */
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;
index 5fd394f..3573c82 100644 (file)
@@ -34,7 +34,7 @@ abstract class tx_form_View_Mail_Html_Element_Abstract {
        /**
         * The model for the current object
         *
-        * @var object
+        * @var tx_form_Domain_Model_Element_Abstract
         */
        protected $model;
 
@@ -353,6 +353,35 @@ abstract class tx_form_View_Mail_Html_Element_Abstract {
        }
 
        /**
+        * Returns the type for the element wraps,
+        * like <li class="csc-form-element csc-form-element-abstract">...</li>
+        *
+        * @return string
+        */
+       public function getElementWrapType() {
+               $elementType = strtolower(
+                       tx_form_Common::getInstance()->getLastPartOfClassName($this->model)
+               );
+               $wrapType = 'csc-form-element csc-form-element-' . $elementType;
+
+               return $wrapType;
+       }
+
+       /**
+        * Returns all element wraps.
+        *
+        * @return string
+        */
+       public function getElementWraps() {
+               $wraps = array(
+                       $this->getElementWrapId(),
+                       $this->getElementWrapType(),
+               );
+
+               return implode(' ', $wraps);
+       }
+
+       /**
         * Read the noWrap value of an element
         * if TRUE the element does not need a element wrap
         * like <li>element</li>
index 9109df3..e5e8f51 100644 (file)
@@ -70,6 +70,9 @@ class tx_form_View_Mail_Html_Element_Container extends tx_form_View_Mail_Html_El
                                        $childNode = $child->render();
                                } else {
                                        $childNode = $child->render('elementWrap');
+                                       if ($childNode) {
+                                               $childNode->setAttribute('class', $child->getElementWraps());
+                                       }
                                }
                                if ($childNode) {
                                        $importedNode = $dom->importNode($childNode, TRUE);
@@ -87,7 +90,7 @@ class tx_form_View_Mail_Html_Element_Container extends tx_form_View_Mail_Html_El
         * Create child object from the classname of the model
         *
         * @param object $modelChild The childs model
-        * @return object
+        * @return tx_form_View_Mail_Html_Element_Abstract
         */
        public function createChildElementFromModel($modelChild) {
                $childElement = NULL;