[BUGFIX] FormViewHelper creates inline styling
authorWouter Wolters <typo3@wouterwolters.nl>
Sun, 3 Mar 2013 16:06:27 +0000 (17:06 +0100)
committerAlexander Schnitzler <typo3@alexanderschnitzler.de>
Tue, 19 Mar 2013 22:41:46 +0000 (23:41 +0100)
Due to accessibility reasons the inline styling of a container is
removed.

Change-Id: I8d3759ebac694a5a4254beb2f7d7561f6c73beaa
Fixes: #40826
Fluid Package Issue: #42743
Releases: 6.1, 6.0, 4.7, 1.3
Reviewed-on: https://review.typo3.org/18573
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Alexander Schnitzler
Tested-by: Alexander Schnitzler
Reviewed-on: https://review.typo3.org/19021
Reviewed-on: https://review.typo3.org/19027

typo3/sysext/fluid/Classes/ViewHelpers/FormViewHelper.php
typo3/sysext/fluid/Tests/Unit/ViewHelpers/FormViewHelperTest.php

index 34e4725..1d7e9b0 100644 (file)
@@ -120,9 +120,10 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
         * @param string $fieldNamePrefix Prefix that will be added to all field names within this form. If not set the prefix will be tx_yourExtension_plugin
         * @param string $actionUri can be used to overwrite the "action" attribute of the form tag
         * @param string $objectName name of the object that is bound to this form. If this argument is not specified, the name attribute of this form is used to determine the FormObjectName
+        * @param string $hiddenFieldClassName
         * @return string rendered form
         */
-       public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $object = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $fieldNamePrefix = NULL, $actionUri = NULL, $objectName = NULL) {
+       public function render($action = NULL, array $arguments = array(), $controller = NULL, $extensionName = NULL, $pluginName = NULL, $pageUid = NULL, $object = NULL, $pageType = 0, $noCache = FALSE, $noCacheHash = FALSE, $section = '', $format = '', array $additionalParams = array(), $absolute = FALSE, $addQueryString = FALSE, array $argumentsToBeExcludedFromQueryString = array(), $fieldNamePrefix = NULL, $actionUri = NULL, $objectName = NULL, $hiddenFieldClassName = NULL) {
                $this->setFormActionUri();
 
                if (strtolower($this->arguments['method']) === 'get') {
@@ -138,7 +139,12 @@ class Tx_Fluid_ViewHelpers_FormViewHelper extends Tx_Fluid_ViewHelpers_Form_Abst
 
                $formContent = $this->renderChildren();
 
-               $content = chr(10) . '<div style="display: none">';
+               if ($this->arguments['hiddenFieldClassName'] !== NULL) {
+                       $content = chr(10) . '<div class="' . htmlspecialchars($this->arguments['hiddenFieldClassName']) . '">';
+               } else {
+                       $content = chr(10) . '<div>';
+               }
+
                $content .= $this->renderHiddenIdentityField($this->arguments['object'], $this->getFormObjectName());
                $content .= $this->renderAdditionalIdentityFields();
                $content .= $this->renderHiddenReferrerFields();
index 1ad4fe3..9ae8f03 100644 (file)
@@ -134,7 +134,7 @@ class Tx_Fluid_Tests_Unit_ViewHelpers_FormViewHelperTest extends Tx_Fluid_ViewHe
                $viewHelper->expects($this->once())->method('renderRequestHashField')->will($this->returnValue('requestHashField'));
                $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('formContent'));
 
-               $expectedResult = chr(10) . '<div style="display: none">' . 'hiddenIdentityFieldadditionalIdentityFieldshiddenReferrerFieldsrequestHashField' . chr(10) . '</div>' . chr(10) . 'formContent';
+               $expectedResult = chr(10) . '<div>' . 'hiddenIdentityFieldadditionalIdentityFieldshiddenReferrerFieldsrequestHashField' . chr(10) . '</div>' . chr(10) . 'formContent';
                $this->tagBuilder->expects($this->once())->method('setContent')->with($expectedResult);
 
                $viewHelper->render();
@@ -145,6 +145,38 @@ class Tx_Fluid_Tests_Unit_ViewHelpers_FormViewHelperTest extends Tx_Fluid_ViewHe
         * @test
         * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
         */
+       public function renderWrapsHiddenFieldsWithDivForXhtmlCompatibilityWithDeprecatedPropertyMapper() {
+               /** @var $viewHelper Tx_Fluid_ViewHelpers_FormViewHelper */
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderAdditionalIdentityFields', 'renderHiddenReferrerFields', 'renderTrustedPropertiesField', 'renderRequestHashField'), array(), '', FALSE);
+               parent::injectDependenciesIntoViewHelper($viewHelper);
+               $viewHelper->expects($this->once())->method('renderHiddenIdentityField')->will($this->returnValue('hiddenIdentityField'));
+               $viewHelper->expects($this->once())->method('renderAdditionalIdentityFields')->will($this->returnValue('additionalIdentityFields'));
+               $viewHelper->expects($this->once())->method('renderHiddenReferrerFields')->will($this->returnValue('hiddenReferrerFields'));
+               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('formContent'));
+               $expectedResult = chr(10) . '<div>' . 'hiddenIdentityFieldadditionalIdentityFieldshiddenReferrerFields' . chr(10) . '</div>' . chr(10) . 'formContent';
+               $this->tagBuilder->expects($this->once())->method('setContent')->with($expectedResult);
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        */
+       public function renderWrapsHiddenFieldsWithDivAndAnAdditionalClassForXhtmlCompatibilityWithDeprecatedPropertyMapper() {
+               $viewHelper = $this->getMock($this->buildAccessibleProxy('Tx_Fluid_ViewHelpers_FormViewHelper'), array('renderChildren', 'renderHiddenIdentityField', 'renderAdditionalIdentityFields', 'renderHiddenReferrerFields', 'renderTrustedPropertiesField', 'renderRequestHashField'), array(), '', FALSE);
+               parent::injectDependenciesIntoViewHelper($viewHelper);
+               $viewHelper->expects($this->once())->method('renderHiddenIdentityField')->will($this->returnValue('hiddenIdentityField'));
+               $viewHelper->expects($this->once())->method('renderAdditionalIdentityFields')->will($this->returnValue('additionalIdentityFields'));
+               $viewHelper->expects($this->once())->method('renderHiddenReferrerFields')->will($this->returnValue('hiddenReferrerFields'));
+               $viewHelper->expects($this->once())->method('renderChildren')->will($this->returnValue('formContent'));
+               $expectedResult = chr(10) . '<div class="hidden">' . 'hiddenIdentityFieldadditionalIdentityFieldshiddenReferrerFields' . chr(10) . '</div>' . chr(10) . 'formContent';
+               $this->tagBuilder->expects($this->once())->method('setContent')->with($expectedResult);
+               $viewHelper->setArguments(new Tx_Fluid_Core_ViewHelper_Arguments(array('hiddenFieldClassName' => 'hidden')));
+               $viewHelper->render();
+       }
+
+       /**
+        * @test
+        */
        public function renderAdditionalIdentityFieldsFetchesTheFieldsFromViewHelperVariableContainerAndBuildsHiddenFieldsForThem() {
                $identityProperties = array(
                        'object1[object2]' => '<input type="hidden" name="object1[object2][__identity]" value="42" />',