Commit 6df86daa authored by Christian Kuhn's avatar Christian Kuhn
Browse files

[BUGFIX] FormEngine databaseRow compatibility with old methods

Introduce a helper method to fake old databaseRow layout at some
places where old methods expect a flat array.

Resolves: #69618
Releases: master
Change-Id: I3657393844f141623187d01744f812cc6fa1adc1
Reviewed-on: http://review.typo3.org/43152

Reviewed-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein's avatarMarkus Klein <markus.klein@typo3.org>
Reviewed-by: Mathias Schreiber's avatarMathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: Mathias Schreiber's avatarMathias Schreiber <mathias.schreiber@wmdb.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
parent 534c8ff2
......@@ -413,7 +413,7 @@ class InlineRecordContainer extends AbstractContainer {
$recTitle = BackendUtility::getNoRecordTitle(TRUE);
}
} else {
$recTitle = BackendUtility::getRecordTitle($foreign_table, $rec, TRUE);
$recTitle = BackendUtility::getRecordTitle($foreign_table, FormEngineUtility::databaseRowCompatibility($rec), TRUE);
}
$altText = BackendUtility::getRecordIconAltText($rec, $foreign_table);
......
......@@ -450,6 +450,39 @@ class FormEngineUtility {
return $itemArray;
}
/**
* Compatibility layer for methods not in FormEngine scope.
*
* databaseRow was a flat array with single elements in select and group fields as comma separated list.
* With new data handling in FormEngine, this is now an array of element values. There are however "old"
* methods that still expect the flat array.
* This method implodes the array again to fake the old behavior of a database row before it is given
* to those methods.
*
* @param array $row Incoming array
* @return array Flat array
* @internal
*/
static public function databaseRowCompatibility(array $row) {
$newRow = [];
foreach ($row as $fieldName => $fieldValue) {
if (!is_array($fieldValue)) {
$newRow[$fieldName] = $fieldValue;
} else {
$newElementValue = [];
foreach ($fieldValue as $itemNumber => $itemValue) {
if (is_array($itemValue) && array_key_exists(1, $itemValue)) {
$newElementValue[] = $itemValue[1];
} else {
$newElementValue[] = $itemValue;
}
}
$newRow[$fieldName] = implode(',', $newElementValue);
}
}
return $newRow;
}
/**
* @return LanguageService
*/
......
<?php
namespace TYPO3\CMS\Backend\Tests\Unit\Form\FormDataProvider;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use TYPO3\CMS\Backend\Form\Utility\FormEngineUtility;
use TYPO3\CMS\Core\Tests\UnitTestCase;
/**
* Test case
*/
class FormEngineUtilityTest extends UnitTestCase {
/**
* @test
*/
public function databaseRowCompatibilityKeepsSimpleValue() {
$input = [
'uid' => 42,
'title' => 'aTitle',
];
$expected = $input;
$this->assertEquals($expected, FormEngineUtility::databaseRowCompatibility($input));
}
/**
* @test
*/
public function databaseRowCompatibilityImplodesSimpleArray() {
$input = [
'uid' => 42,
'simpleArray' => [
0 => 1,
1 => 2,
],
];
$expected = $input;
$expected['simpleArray'] = '1,2';
$this->assertEquals($expected, FormEngineUtility::databaseRowCompatibility($input));
}
/**
* @test
*/
public function databaseRowCompatibilityImplodesSelectArrayWithValuesAtSecondPosition() {
$input = [
'uid' => 42,
'simpleArray' => [
0 => [
0 => 'aLabel',
1 => 'aValue',
],
1 => [
0 => 'anotherLabel',
1 => 'anotherValue',
],
],
];
$expected = $input;
$expected['simpleArray'] = 'aValue,anotherValue';
$this->assertEquals($expected, FormEngineUtility::databaseRowCompatibility($input));
}
}
Supports Markdown
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