[BUGFIX] EXT:form - Cannot set some f:form arguments via TS 15/47015/5
authorRalf Zimmermann <ralf.zimmermann@tritum.de>
Thu, 3 Mar 2016 17:19:04 +0000 (18:19 +0100)
committerFrans Saris <franssaris@gmail.com>
Thu, 17 Mar 2016 09:58:45 +0000 (10:58 +0100)
Render array viewhelper attributes as array.

Resolves: #74014
Releases: master, 7.6
Change-Id: I2abcea032a6d58c610b57a9b07d0380567473eeb
Reviewed-on: https://review.typo3.org/47015
Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Daniel Goerz <ervaude@gmail.com>
Tested-by: Daniel Goerz <ervaude@gmail.com>
Reviewed-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Ruud Silvrants <ruudsilvrants@gmail.com>
Tested-by: Ruud Silvrants <ruudsilvrants@gmail.com>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frans Saris <franssaris@gmail.com>
typo3/sysext/form/Classes/Domain/Builder/ElementBuilder.php
typo3/sysext/form/Classes/Utility/FormUtility.php

index 9b2b9fe..57197a2 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)
@@ -272,7 +286,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']);
@@ -286,7 +301,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 (
@@ -303,10 +320,18 @@ class ElementBuilder
             $attributeNameWithoutDot = rtrim($attributeName, '.');
             $attributeNameToSet = $attributeNameWithoutDot;
 
-            $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