[BUGFIX] EXT:form - class attribute in container elements is not shown 20/43520/10
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Sat, 26 Sep 2015 18:08:18 +0000 (20:08 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 28 Sep 2015 05:44:01 +0000 (07:44 +0200)
If a layout for FORM or FIELDSET is definded and it contains a
class attribute, the class attribute is not set in the template.

Resolves: #70070
Releases: master
Change-Id: Ib527cd269383932306805256415e273a76339cb6
Reviewed-on: http://review.typo3.org/43520
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/form/Classes/Utility/CompatibilityLayerUtility.php

index a368079..27d1267 100644 (file)
@@ -201,6 +201,13 @@ class CompatibilityLayerUtility {
                        $formContainerWrap = explode($containerWrapReturn['marker'], $formLayout);
                        $layout['containerInnerWrap'] = $formContainerWrap;
                        $element->setLayout($layout);
+                       $classFromLayout = $this->getElementClassFromLayout('form');
+                       if (!empty($classFromLayout)) {
+                               if (!empty($element->getAdditionalArgument('class'))) {
+                                       $classFromLayout .= ' ' . $element->getAdditionalArgument('class');
+                               }
+                               $element->setAdditionalArgument('class', $classFromLayout);
+                       }
                        return;
                }
                if (in_array($element->getElementType(), $this->registeredFormElements)) {
@@ -288,7 +295,7 @@ class CompatibilityLayerUtility {
                                if ($dom) {
                                        $node = $dom->firstChild;
                                        if ($node) {
-                                               if (strlen($node->getAttribute('class')) > 0) {
+                                               if ($node->getAttribute('class') !== '') {
                                                        $class = $node->getAttribute('class') . ' ';
                                                }
                                                $class .= 'csc-form-' . $element->getElementCounter() . ' csc-form-element csc-form-element-' . $element->getElementTypeLowerCase();
@@ -351,6 +358,13 @@ class CompatibilityLayerUtility {
                                $layout = $element->getLayout();
                                $layout['containerInnerWrap'] = $containerWrap;
                                $element->setLayout($layout);
+                               $classFromLayout = $this->getElementClassFromLayout('fieldset');
+                               if (!empty($classFromLayout)) {
+                                       if (!empty($element->getHtmlAttribute('class'))) {
+                                               $classFromLayout .= ' ' . $element->getHtmlAttribute('class');
+                                       }
+                                       $element->setHtmlAttribute('class', $classFromLayout);
+                               }
                        }
                        return;
                }
@@ -372,6 +386,31 @@ class CompatibilityLayerUtility {
        }
 
        /**
+        * Return the class attribute for a element defined by layout.
+        *
+        * @param string $elementName
+        * @return string
+        */
+       protected function getElementClassFromLayout($elementName = '') {
+               $class = '';
+               $libxmlUseInternalErrors = libxml_use_internal_errors(true);
+               $dom = new \DOMDocument('1.0', 'utf-8');
+               $dom->formatOutput = TRUE;
+               $dom->preserveWhiteSpace = FALSE;
+               if ($dom->loadXML($this->getGlobalLayoutByElementType(strtoupper($elementName)))) {
+                       $nodes = $dom->getElementsByTagName($elementName);
+                       if ($nodes->length) {
+                               $node = $nodes->item(0);
+                               if ($node && $node->getAttribute('class') !== '') {
+                                       $class = $node->getAttribute('class');
+                               }
+                       }
+               }
+               libxml_use_internal_errors($libxmlUseInternalErrors);
+               return $class;
+       }
+
+       /**
         * Try to explode the element layout into 2 parts to get the
         * outer wrapping
         *