[BUGFIX] Pass FlexForm context to USER display condition 70/58770/2
authorNicole Cordes <typo3@cordes.co>
Thu, 27 Sep 2018 14:23:21 +0000 (16:23 +0200)
committerBenni Mack <benni@typo3.org>
Sun, 28 Oct 2018 16:04:07 +0000 (17:04 +0100)
If using a user display condition within a FlexForm field,
the passed information is insufficient and information about the
parsed FlexForm is missing.

Resolves: #86403
Releases: master, 8.7
Change-Id: I9917b3f98f7d7eb4fa3370e1cd2e9a9cd0eef627
Reviewed-on: https://review.typo3.org/58770
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php
typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php

index 8a66353..14910ff 100644 (file)
@@ -426,6 +426,7 @@ class EvaluateDisplayConditions implements FormDataProviderInterface
                     );
                 $namedConditionArray['parameters'] = $parameters;
                 $namedConditionArray['record'] = $databaseRow;
+                $namedConditionArray['flexContext'] = $flexContext;
                 break;
             default:
                 throw new \RuntimeException(
@@ -923,6 +924,7 @@ class EvaluateDisplayConditions implements FormDataProviderInterface
     {
         $parameter = [
             'record' => $condition['record'],
+            'flexContext' => $condition['flexContext'],
             'flexformValueKey' => 'vDEF',
             'conditionParameters' => $condition['parameters'],
         ];
index d21a7e3..c5ddd35 100644 (file)
@@ -547,6 +547,7 @@ class EvaluateDisplayConditionsTest extends \TYPO3\TestingFramework\Core\Unit\Un
     {
         $expected = [
             'record' => [],
+            'flexContext' => [],
             'flexformValueKey' => 'vDEF',
             'conditionParameters' => [
                 0 => 'more',
@@ -609,6 +610,88 @@ class EvaluateDisplayConditionsTest extends \TYPO3\TestingFramework\Core\Unit\Un
     /**
      * @test
      */
+    public function addDataPassesFlexContextToUserCondition()
+    {
+        $input = [
+            'databaseRow' => [],
+            'processedTca' => [
+                'columns' => [
+                    'field_1' => [
+                        'config' => [
+                            'type' => 'flex',
+                            'ds' => [
+                                'sheets' => [
+                                    'sDEF' => [
+                                        'ROOT' => [
+                                            'type' => 'array',
+                                            'el' => [
+                                                'foo' => [
+                                                    'displayCond' => 'USER:' . self::class . '->addDataPassesFlexContextToUserConditionCallback:some:info',
+                                                ],
+                                            ],
+                                        ],
+                                    ],
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+        ];
+
+        $expected = $input;
+        unset($expected['processedTca']['columns']['field_1']['config']['ds']['sheets']['sDEF']['ROOT']['el']['foo']['displayCond']);
+
+        $this->assertSame($expected, (new EvaluateDisplayConditions())->addData($input));
+    }
+
+    /**
+     * Callback method of addDataEvaluatesUserCondition. A USER condition
+     * Throws an exception if data is correct!
+     *
+     * @param array $parameter
+     * @throws \RuntimeException if FlexForm context is not as expected
+     * @return bool
+     */
+    public function addDataPassesFlexContextToUserConditionCallback(array $parameter)
+    {
+        $expected = [
+            'context' => 'flexField',
+            'sheetNameFieldNames' => [
+                'sDEF.foo' => [
+                    'sheetName' => 'sDEF',
+                    'fieldName' => 'foo',
+                ],
+            ],
+            'currentSheetName' => 'sDEF',
+            'currentFieldName' => 'foo',
+            'flexFormDataStructure' => [
+                'sheets' => [
+                    'sDEF' => [
+                        'ROOT' => [
+                            'type' => 'array',
+                            'el' => [
+                                'foo' => [
+                                    'displayCond' => 'USER:' . self::class . '->addDataPassesFlexContextToUserConditionCallback:some:info'
+                                ],
+                            ],
+                        ],
+                    ],
+                ],
+            ],
+            'flexFormRowData' => null,
+        ];
+
+        if ($expected !== $parameter['flexContext']) {
+            throw new \RuntimeException('testing', 1538057402);
+        }
+
+        return true;
+    }
+
+    /**
+     * @test
+     */
     public function addDataThrowsExceptionIfFlexSheetNameAndFieldNameCombinationsOverlap()
     {
         $input = [