Skip to content

Commit

Permalink
[BUGFIX] Allow overrideChildTca in type File
Browse files Browse the repository at this point in the history
Fixes: #179
  • Loading branch information
nhovratov committed Apr 11, 2024
1 parent ea77d84 commit e9019fc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Classes/FieldType/FileFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final class FileFieldType implements FieldTypeInterface
private bool $readOnly = false;
private int $minitems = 0;
private int $maxitems = 0;
private array $overrideChildTca = [];
private bool $extendedPalette = true;
private array $cropVariants = [];

Expand Down Expand Up @@ -69,6 +70,7 @@ public static function createFromArray(array $settings): FileFieldType
$self->readOnly = (bool)($settings['readOnly'] ?? $self->readOnly);
$self->minitems = (int)($settings['minitems'] ?? $self->minitems);
$self->maxitems = (int)($settings['maxitems'] ?? $self->maxitems);
$self->overrideChildTca = (array)($settings['overrideChildTca'] ?? $self->overrideChildTca);
$self->extendedPalette = (bool)($settings['extendedPalette'] ?? $self->extendedPalette);
$self->cropVariants = (array)($settings['cropVariants'] ?? $self->cropVariants);
return $self;
Expand Down Expand Up @@ -99,20 +101,14 @@ public function getTca(): array
if ($this->maxitems > 0) {
$config['maxitems'] = $this->maxitems;
}
if ($this->overrideChildTca !== []) {
$config['overrideChildTca'] = $this->overrideChildTca;
}
if (!$this->extendedPalette) {
$config['overrideChildTca'] = [
'types' => [
AbstractFile::FILETYPE_IMAGE => [
'showitem' => '--palette--;;basicoverlayPalette,--palette--;;filePalette',
],
AbstractFile::FILETYPE_AUDIO => [
'showitem' => '--palette--;;basicoverlayPalette,--palette--;;filePalette',
],
AbstractFile::FILETYPE_VIDEO => [
'showitem' => '--palette--;;basicoverlayPalette,--palette--;;filePalette',
],
],
];
$basicPalette = '--palette--;;basicoverlayPalette,--palette--;;filePalette';
$config['overrideChildTca']['types'][AbstractFile::FILETYPE_IMAGE]['showitem'] = $basicPalette;
$config['overrideChildTca']['types'][AbstractFile::FILETYPE_AUDIO]['showitem'] = $basicPalette;
$config['overrideChildTca']['types'][AbstractFile::FILETYPE_VIDEO]['showitem'] = $basicPalette;
}
if ($this->cropVariants !== []) {
$config['overrideChildTca']['columns']['crop']['config']['cropVariants'] = $this->processCropVariants();
Expand Down
5 changes: 5 additions & 0 deletions Tests/Unit/FieldTypes/FileFieldTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'behaviour' => [
'foo' => 'bar',
],
'overrideChildTca' => [
'foo' => 'bar',
],
'readOnly' => 1,
'minitems' => 1,
'maxitems' => 1,
Expand Down Expand Up @@ -110,6 +113,7 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'minitems' => 1,
'maxitems' => 1,
'overrideChildTca' => [
'foo' => 'bar',
'columns' => [
'crop' => [
'config' => [
Expand Down Expand Up @@ -174,6 +178,7 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'minitems' => 0,
'maxitems' => 0,
'cropVariants' => [],
'overrideChildTca' => [],
],
'expectedTca' => [
'config' => [
Expand Down

0 comments on commit e9019fc

Please sign in to comment.