-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Clean up config when loading definition
Config cleanup is important, to get rid of old configuration, which is not available anymore. This happens of course after on-the-fly migration is completed. Prior to this, config cleanup was only done in the FieldsController. The intent here was to only present valid data to VueJS. Impact: When saving or running the mask:convert command, obsolete configuration is removed. (cherry picked from commit ee8fda7)
- Loading branch information
Showing
10 changed files
with
202 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* 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! | ||
*/ | ||
|
||
namespace MASK\Mask\Loader; | ||
|
||
use MASK\Mask\Definition\TableDefinitionCollection; | ||
use MASK\Mask\Utility\TcaConverter; | ||
|
||
trait ConfigCleanerTrait | ||
{ | ||
use WithConfigurationLoaderTrait; | ||
|
||
/** | ||
* This method removes all tca options defined which aren't available in Mask. | ||
*/ | ||
public function cleanUpConfig(TableDefinitionCollection $tableDefinitionCollection): void | ||
{ | ||
foreach ($tableDefinitionCollection as $tableDefinition) { | ||
foreach ($tableDefinition->tca as $tcaFieldDefinition) { | ||
$tabConfig = $this->configurationLoader->loadTab((string)$tcaFieldDefinition->type); | ||
$tcaOptions = []; | ||
foreach ($tabConfig as $options) { | ||
foreach ($options as $row) { | ||
$tcaOptions[] = array_keys($row); | ||
} | ||
} | ||
$tcaOptions = array_merge([], ...$tcaOptions); | ||
|
||
$tcaFieldDefinition->realTca = array_filter(TcaConverter::convertTcaArrayToFlat($tcaFieldDefinition->realTca), static function ($key) use ($tcaOptions) { | ||
return in_array($key, $tcaOptions, true); | ||
}, ARRAY_FILTER_USE_KEY); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* 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! | ||
*/ | ||
|
||
|
||
namespace MASK\Mask\Loader; | ||
|
||
use MASK\Mask\ConfigurationLoader\ConfigurationLoaderInterface; | ||
|
||
trait WithConfigurationLoaderTrait | ||
{ | ||
/** | ||
* @var ConfigurationLoaderInterface | ||
*/ | ||
protected $configurationLoader; | ||
|
||
public function setConfigurationLoader(ConfigurationLoaderInterface $configurationLoader): void | ||
{ | ||
$this->configurationLoader = $configurationLoader; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<?php | ||
|
||
namespace MASK\Mask\Tests\Unit\Loader; | ||
|
||
use MASK\Mask\Definition\TableDefinitionCollection; | ||
use MASK\Mask\Loader\ConfigCleanerTrait; | ||
use MASK\Mask\Tests\Unit\ConfigurationLoader\FakeConfigurationLoader; | ||
use MASK\Mask\Tests\Unit\PackageManagerTrait; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
class ConfigCleanerTraitTest extends UnitTestCase | ||
{ | ||
protected $resetSingletonInstances = true; | ||
|
||
use PackageManagerTrait; | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function cleanupConfig(): void | ||
{ | ||
$this->registerPackageManager(); | ||
|
||
$loader = new class { | ||
use ConfigCleanerTrait; | ||
}; | ||
|
||
$loader->setConfigurationLoader(new FakeConfigurationLoader()); | ||
|
||
$input = [ | ||
'tt_content' => [ | ||
'elements' => [ | ||
'element1' => [ | ||
'key' => 'element1', | ||
'label' => 'Element 1', | ||
'labels' => [ | ||
'RTE Field', | ||
], | ||
'columns' => [ | ||
'tx_mask_rte', | ||
], | ||
], | ||
], | ||
'tca' => [ | ||
'tx_mask_rte' => [ | ||
'key' => 'rte', | ||
'config' => [ | ||
'type' => 'text', | ||
'foo' => 'bar' | ||
], | ||
'type' => 'richtext', | ||
'exclude' => '1', | ||
'defaultExtras' => 'richtext[]:rte_transform[mode=ts_css]' | ||
], | ||
], | ||
], | ||
]; | ||
|
||
$expected = [ | ||
'tt_content' => [ | ||
'elements' => [ | ||
'element1' => [ | ||
'key' => 'element1', | ||
'label' => 'Element 1', | ||
'description' => '', | ||
'shortLabel' => '', | ||
'color' => '', | ||
'icon' => '', | ||
'descriptions' => [], | ||
'columns' => [ | ||
'tx_mask_rte', | ||
], | ||
'labels' => [ | ||
'RTE Field', | ||
], | ||
'sorting' => 0 | ||
] | ||
], | ||
'tca' => [ | ||
'tx_mask_rte' => [ | ||
'key' => 'rte', | ||
'fullKey' => 'tx_mask_rte', | ||
'type' => 'richtext', | ||
] | ||
], | ||
'sql' => [], | ||
'palettes' => [] | ||
] | ||
]; | ||
|
||
$tableDefinitionCollection = TableDefinitionCollection::createFromArray($input); | ||
$loader->cleanUpConfig($tableDefinitionCollection); | ||
self::assertEquals($expected, $tableDefinitionCollection->toArray()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters