Skip to content
Snippets Groups Projects
Commit 07dabf60 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Christian Kuhn
Browse files

[TASK] FormEngine: Split TcaTypesShowitem provider

Split the TcaTypesShowitem provider to only deal with resolving
the showitem list. The actual removal of columns not referenced in
either in the showitem list or in one of the palettes is done by the
TcaTypesRemoveUnusedColumns provider.

Resolves: #69821
Releases: master
Change-Id: I2cf988ca375a09d4f62e2cdbf1566fb9e449447e
Reviewed-on: http://review.typo3.org/43329


Reviewed-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: default avatarMorton Jonuschat <m.jonuschat@mojocode.de>
Reviewed-by: default avatarOliver Hader <oliver.hader@typo3.org>
Reviewed-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: default avatarMathias Schreiber <mathias.schreiber@wmdb.de>
Tested-by: default avatarMathias Schreiber <mathias.schreiber@wmdb.de>
parent ae18ac11
Branches
Tags
No related merge requests found
<?php
namespace TYPO3\CMS\Backend\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\FormDataProviderInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Remove fields from columns not in showitem or palette list.
* This is a relatively effective performance improvement preventing other
* providers from resolving stuff of fields that are not shown later.
* Especially effective for fal related tables.
*/
class TcaTypesRemoveUnusedColumns implements FormDataProviderInterface {
/**
* Remove unused column fields to speed up further processing.
*
* @param array $result
* @return array
*/
public function addData(array $result) {
$recordTypeValue = $result['recordTypeValue'];
if (empty($result['processedTca']['types'][$recordTypeValue]['showitem'])
|| !is_string($result['processedTca']['types'][$recordTypeValue]['showitem'])
|| empty($result['processedTca']['columns'])
|| !is_array($result['processedTca']['columns'])
) {
return $result;
}
$showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
$showItemFieldArray = GeneralUtility::trimExplode(',', $showItemFieldString, TRUE);
$shownColumnFields = [];
foreach ($showItemFieldArray as $fieldConfigurationString) {
$fieldConfigurationArray = GeneralUtility::trimExplode(';', $fieldConfigurationString);
$fieldName = $fieldConfigurationArray[0];
if ($fieldName === '--div--') {
continue;
}
if ($fieldName === '--palette--') {
if (isset($fieldConfigurationArray[2])) {
$paletteName = $fieldConfigurationArray[2];
if (!empty($result['processedTca']['palettes'][$paletteName]['showitem'])) {
$paletteFields = GeneralUtility::trimExplode(',', $result['processedTca']['palettes'][$paletteName]['showitem'], TRUE);
foreach ($paletteFields as $paletteFieldConfiguration) {
$paletteFieldConfigurationArray = GeneralUtility::trimExplode(';', $paletteFieldConfiguration);
$shownColumnFields[] = $paletteFieldConfigurationArray[0];
}
}
}
} else {
$shownColumnFields[] = $fieldName;
}
}
array_unique($shownColumnFields);
$columns = array_keys($result['processedTca']['columns']);
foreach ($columns as $column) {
if (!in_array($column, $shownColumnFields)) {
unset($result['processedTca']['columns'][$column]);
}
}
return $result;
}
}
......@@ -19,7 +19,8 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
/**
* Create final showitem configuration in processedTca for types and palette fields
* Create final showitem configuration in processedTca for types and palette
* fields
* Handles all the nasty defails like subtypes_addlist and friends.
*/
class TcaTypesShowitem implements FormDataProviderInterface {
......@@ -69,8 +70,6 @@ class TcaTypesShowitem implements FormDataProviderInterface {
}
}
$result = $this->removeObsoleteColumns($result);
// Handling of these parameters is finished. Unset them to not allow other handlers to fiddle with it.
// unset does not throw notice, even if not set
unset($result['processedTca']['types'][$recordTypeValue]['subtype_value_field']);
......@@ -263,54 +262,4 @@ class TcaTypesShowitem implements FormDataProviderInterface {
return $result;
}
/**
* Remove fields from columns not in showitem or palette list.
* This is a relatively effective performance improvement preventing other providers from
* resolving stuff of fields that are not show later. Especially effective for fal related tables
*
* @param array $result Given result
* @return array Modified result
* @todo: Unit tests missing for this one
*/
protected function removeObsoleteColumns(array $result) {
$recordTypeValue = $result['recordTypeValue'];
if (!empty($result['processedTca']['types'][$recordTypeValue]['showitem'])
&& is_string($result['processedTca']['types'][$recordTypeValue]['showitem'])
&& !empty($result['processedTca']['columns'])
&& is_array($result['processedTca']['columns'])
) {
$showItemFieldString = $result['processedTca']['types'][$recordTypeValue]['showitem'];
$showItemFieldArray = GeneralUtility::trimExplode(',', $showItemFieldString, TRUE);
$shownColumnFields = [];
foreach ($showItemFieldArray as $index => $fieldConfigurationString) {
$fieldConfigurationArray = GeneralUtility::trimExplode(';', $fieldConfigurationString);
$fieldName = $fieldConfigurationArray[0];
if ($fieldName === '--div--') {
continue;
}
if ($fieldName === '--palette--') {
if (isset($fieldConfigurationArray[2])) {
$paletteName = $fieldConfigurationArray[2];
if (!empty($result['processedTca']['palettes'][$paletteName]['showitem'])) {
$paletteFields = GeneralUtility::trimExplode(',', $result['processedTca']['palettes'][$paletteName]['showitem'], TRUE);
foreach ($paletteFields as $paletteFieldConfiguration) {
$paletteFieldConfigurationArray = GeneralUtility::trimExplode(';', $paletteFieldConfiguration);
$shownColumnFields[] = $paletteFieldConfigurationArray[0];
}
}
}
} else {
$shownColumnFields[] = $fieldName;
}
}
array_unique($shownColumnFields);
$columns = array_keys($result['processedTca']['columns']);
foreach ($columns as $column) {
if (!in_array($column, $shownColumnFields)) {
unset ($result['processedTca']['columns'][$column]);
}
}
}
return $result;
}
}
<?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\FormDataProvider\TcaTypesRemoveUnusedColumns;
use TYPO3\CMS\Core\Tests\UnitTestCase;
/**
* Test case
*/
class TcaTypesRemoveUnusedColumnsTest extends UnitTestCase {
/**
* @var TcaTypesRemoveUnusedColumns
*/
protected $subject;
public function setUp() {
$this->subject = new TcaTypesRemoveUnusedColumns();
}
/**
* @test
*/
public function addDataKeepsColumnsFieldReferencedInShowitems() {
$input = [
'databaseRow' => [],
'recordTypeValue' => 'aType',
'processedTca' => [
'types' => [
'aType' => [
'showitem' => 'keepMe'
],
],
'columns' => [
'keepMe' => [
'config' => [
'type' => 'input',
]
],
'aField' => [
'config' => [
'type' => 'input',
]
]
]
]
];
$expected = $input;
unset($expected['processedTca']['columns']['aField']);
$this->assertSame($expected, $this->subject->addData($input));
}
/**
* @test
*/
public function addDataKeepsColumnsFieldReferencedInPalette() {
$input = [
'databaseRow' => [],
'recordTypeValue' => 'aType',
'processedTca' => [
'types' => [
'aType' => [
'showitem' => '--palette--;;aPalette'
],
],
'palettes' => [
'aPalette' => array(
'showitem' => 'keepMe',
'canNotCollapse' => TRUE
),
],
'columns' => [
'keepMe' => [
'config' => [
'type' => 'input',
]
],
'bField' => [
'config' => [
'type' => 'input',
]
]
]
]
];
$expected = $input;
unset($expected['processedTca']['columns']['bField']);
$this->assertSame($expected, $this->subject->addData($input));
}
/**
* @test
*/
public function addDataRemovesColumnsNotReferencedInShowitemOrPalette() {
$input = [
'databaseRow' => [],
'recordTypeValue' => 'aType',
'processedTca' => [
'types' => [
'aType' => [
'showitem' => '--palette--;;aPalette, anotherField'
],
],
'palettes' => [
'aPalette' => array(
'showitem' => 'aField',
'canNotCollapse' => TRUE
),
],
'columns' => [
'aField' => [
'config' => [
'type' => 'input',
]
],
'removeMe' => [
'config' => [
'type' => 'input',
]
],
'anotherField' => [
'config' => [
'type' => 'input',
]
]
]
]
];
$expected = $input;
unset($expected['processedTca']['columns']['removeMe']);
$this->assertSame($expected, $this->subject->addData($input));
}
}
......@@ -409,12 +409,17 @@ return array(
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaColumnsOverrides::class
),
),
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesRemoveUnusedColumns::class => array(
'depends' => array(
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem::class
),
),
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexFetch::class => array(
'depends' => array(
\TYPO3\CMS\Backend\Form\FormDataProvider\InitializeProcessedTca::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\UserTsConfig::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\PageTsConfigMerged::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesRemoveUnusedColumns::class,
),
),
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexPrepare::class => array(
......@@ -445,6 +450,7 @@ return array(
\TYPO3\CMS\Backend\Form\FormDataProvider\PageTsConfigMerged::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\InitializeProcessedTca::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesShowitem::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaTypesRemoveUnusedColumns::class,
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaCheckboxItems::class,
// GeneralUtility::getFlexFormDS() needs unchanged databaseRow values as string
\TYPO3\CMS\Backend\Form\FormDataProvider\TcaFlexFetch::class,
......
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