From a44b53fd032d50ede53bdd083194ed2c46e1f1c5 Mon Sep 17 00:00:00 2001 From: Anja Leichsenring <aleichsenring@ab-softlab.de> Date: Thu, 1 Oct 2015 14:44:56 +0200 Subject: [PATCH] [BUGFIX] Evaluate displayConditions based on array values With the rewrite of the FormEngine, all data defined as select fields in TCA became arrays in the data provision. Therefore displayConditions based on single values are not evaluated correctly anymore. A check was added, when the array contains only one value, this one is used to perform the evaluation. Change-Id: If43067eb5d19748afce02b41ce44a14ca4b7fa1f Resolves: #70265 Releases: master Reviewed-on: http://review.typo3.org/43693 Reviewed-by: Andreas Fernandez <typo3@scripting-base.de> Tested-by: Andreas Fernandez <typo3@scripting-base.de> Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl> Tested-by: Wouter Wolters <typo3@wouterwolters.nl> Reviewed-by: Georg Ringer <georg.ringer@gmail.com> Tested-by: Georg Ringer <georg.ringer@gmail.com> --- .../EvaluateDisplayConditions.php | 18 +++++++++++ .../EvaluateDisplayConditionsTest.php | 30 +++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php b/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php index 5937c0104bf6..af0c25da7f94 100644 --- a/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php +++ b/typo3/sysext/backend/Classes/Form/FormDataProvider/EvaluateDisplayConditions.php @@ -332,6 +332,9 @@ class EvaluateDisplayConditions implements FormDataProviderInterface { $result = FALSE; switch ($operator) { case 'REQ': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } if (strtoupper($operand) === 'TRUE') { $result = (bool)$fieldValue; } else { @@ -339,19 +342,34 @@ class EvaluateDisplayConditions implements FormDataProviderInterface { } break; case '>': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } $result = $fieldValue > $operand; break; case '<': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } $result = $fieldValue < $operand; break; case '>=': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } $result = $fieldValue >= $operand; break; case '<=': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } $result = $fieldValue <= $operand; break; case '-': case '!-': + if (is_array($fieldValue) && count($fieldValue) === 1) { + $fieldValue = array_shift($fieldValue); + } list($minimum, $maximum) = explode('-', $operand); $result = $fieldValue >= $minimum && $fieldValue <= $maximum; if ($operator[0] === '!') { diff --git a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php index 9201236b29f1..d9fe493c13ac 100644 --- a/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php +++ b/typo3/sysext/backend/Tests/Unit/Form/FormDataProvider/EvaluateDisplayConditionsTest.php @@ -601,6 +601,36 @@ class EvaluateDisplayConditionsTest extends UnitTestCase { $this->assertSame($expected, $this->subject->addData($input)); } + /** + * @param string $condition + * @param array $record + * @param string $expectedResult + * + * @dataProvider conditionStringDataProvider + * @test + */ + public function matchConditionStringsWithRecordTestFieldBeingArray($condition, array $record, $expectedResult) { + $input = [ + 'processedTca' => [ + 'columns' => [ + 'testField' => [ + 'displayCond' => $condition, + 'config' => [ + 'type' => 'input', + ], + ], + ], + ], + ]; + $input['databaseRow'] = $record ?: ['testField' => ['key' => $record['testField']]]; + + $expected = $input; + if (!$expectedResult) { + unset($expected['processedTca']['columns']['testField']); + } + $this->assertSame($expected, $this->subject->addData($input)); + } + /** * Returns data sets for the test matchConditionStrings * Each data set is an array with the following elements: -- GitLab