Skip to content
Snippets Groups Projects
Commit a44b53fd authored by Anja Leichsenring's avatar Anja Leichsenring Committed by Georg Ringer
Browse files

[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: default avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: default avatarAndreas Fernandez <typo3@scripting-base.de>
Reviewed-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Tested-by: default avatarWouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
Tested-by: default avatarGeorg Ringer <georg.ringer@gmail.com>
parent e3abec18
Branches
Tags
No related merge requests found
......@@ -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] === '!') {
......
......@@ -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:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment