[BUGFIX] EXT:form - Fix setting of additional f:form arguments via TS 82/47582/3
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Mon, 11 Apr 2016 19:02:51 +0000 (21:02 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 23 Jun 2016 19:57:38 +0000 (21:57 +0200)
Render array viewhelper attributes correctly to allow setting additional
f:form arguments via TS.

Resolves: #74014
Releases: master, 7.6
Change-Id: I2abcea032a6d58c610b57a9b07d0380567473eeb
Reviewed-on: https://review.typo3.org/47582
Reviewed-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/form/Classes/Domain/Builder/ElementBuilder.php
typo3/sysext/form/Classes/Utility/FormUtility.php

index 36e5b6b..fd13ace 100644 (file)
@@ -44,6 +44,11 @@ class ElementBuilder
     protected $typoScriptRepository;
 
     /**
+     * @var \TYPO3\CMS\Extbase\Service\TypoScriptService
+     */
+    protected $typoScriptService;
+
+    /**
      * @var array
      */
     protected $userConfiguredElementTyposcript = array();
@@ -83,6 +88,15 @@ class ElementBuilder
     }
 
     /**
+     * @param \TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService
+     * @return void
+     */
+    public function injectTypoScriptService(\TYPO3\CMS\Extbase\Service\TypoScriptService $typoScriptService)
+    {
+        $this->typoScriptService = $typoScriptService;
+    }
+
+    /**
      * @param FormBuilder $formBuilder
      */
     public function setFormBuilder(FormBuilder $formBuilder)
@@ -299,7 +313,8 @@ class ElementBuilder
         $viewHelperDefaultArguments = $this->typoScriptRepository->getModelConfigurationByScope($this->element->getElementType(), 'viewHelperDefaultArguments.');
         if (is_array($viewHelperDefaultArguments)) {
             foreach ($viewHelperDefaultArguments as $viewHelperDefaulArgumentName => $viewHelperDefaulArgumentValue) {
-                $this->additionalArguments[$viewHelperDefaulArgumentName] = $viewHelperDefaulArgumentValue;
+                $viewHelperDefaulArgumentNameWithoutDot = rtrim($viewHelperDefaulArgumentName, '.');
+                $this->additionalArguments[$viewHelperDefaulArgumentNameWithoutDot] = $viewHelperDefaulArgumentValue;
             }
         }
         unset($this->userConfiguredElementTyposcript['viewHelperDefaultArguments']);
@@ -313,7 +328,9 @@ class ElementBuilder
      */
     public function moveAllOtherUserdefinedPropertiesToAdditionalArguments()
     {
+        $viewHelperDefaultArguments = $this->typoScriptRepository->getModelConfigurationByScope($this->element->getElementType(), 'viewHelperDefaultArguments.');
         $ignoreKeys = array();
+
         foreach ($this->userConfiguredElementTyposcript as $attributeName => $attributeValue) {
             // ignore child elements
             if (
@@ -356,10 +373,18 @@ class ElementBuilder
                 }
             }
             if ($rendered === false) {
-                $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
-                    $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'],
-                    $this->userConfiguredElementTyposcript[$attributeNameWithoutDot]
-                );
+                if (
+                    isset($viewHelperDefaultArguments[$attributeName])
+                    || isset($viewHelperDefaultArguments[$attributeNameWithoutDot])
+                ) {
+                    $this->formBuilder->getFormUtility()->renderArrayItems($attributeValue);
+                    $attributeValue = $this->typoScriptService->convertTypoScriptArrayToPlainArray($attributeValue);
+                } else {
+                    $attributeValue = $this->formBuilder->getFormUtility()->renderItem(
+                        $this->userConfiguredElementTyposcript[$attributeNameWithoutDot . '.'],
+                        $this->userConfiguredElementTyposcript[$attributeNameWithoutDot]
+                    );
+                }
                 $this->additionalArguments[$attributeNameToSet] = $attributeValue;
                 $ignoreKeys[$attributeNameToSet . '.'] = true;
                 $ignoreKeys[$attributeNameToSet] = true;
index 869ab36..fcd34c1 100644 (file)
@@ -196,6 +196,35 @@ class FormUtility
     }
 
     /**
+     * Render array values recursively as cObjects using the
+     * method renderItem.
+     *
+     * @param array $arrayToRender
+     * @return array
+     */
+    public function renderArrayItems(array &$arrayToRender = array())
+    {
+        foreach ($arrayToRender as $attributeName => &$attributeValue) {
+            $attributeNameWithoutDot = rtrim($attributeName, '.');
+            if (
+                isset($arrayToRender[$attributeNameWithoutDot])
+                && isset($arrayToRender[$attributeNameWithoutDot . '.'])
+            ) {
+                $attributeValue = $this->renderItem(
+                    $arrayToRender[$attributeNameWithoutDot . '.'],
+                    $arrayToRender[$attributeNameWithoutDot]
+                );
+                unset($arrayToRender[$attributeNameWithoutDot . '.']);
+            } elseif (
+                !isset($arrayToRender[$attributeNameWithoutDot])
+                && isset($arrayToRender[$attributeNameWithoutDot . '.'])
+            ) {
+                $this->renderArrayItems($attributeValue);
+            }
+        }
+    }
+
+    /**
      * If the name is not defined it is automatically generated
      * using the following syntax: id-{element_counter}
      * The name attribute will be transformed if it contains some