Skip to content

Commit

Permalink
[TASK] Allow dbFieldLength option for select
Browse files Browse the repository at this point in the history
  • Loading branch information
nhovratov committed Dec 2, 2024
1 parent 9c932a7 commit 0e12f73
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Classes/FieldType/SelectFieldType.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ final class SelectFieldType extends AbstractFieldType
// Only for renderType="selectTree"
private array $treeConfig = [];
private string $relationship = '';
private int $dbFieldLength = 0;

public function createFromArray(array $settings): SelectFieldType
{
Expand Down Expand Up @@ -99,6 +100,7 @@ public function createFromArray(array $settings): SelectFieldType
) {
$self->relationship = 'manyToOne';
}
$self->dbFieldLength = (int)($settings['dbFieldLength'] ?? $self->dbFieldLength);
$self->setCustomProperties($settings);

return $self;
Expand Down Expand Up @@ -187,6 +189,9 @@ public function getTca(): array
if ($this->relationship !== '') {
$config['relationship'] = $this->relationship;
}
if ($this->dbFieldLength !== 0) {
$config['dbFieldLength'] = $this->dbFieldLength;
}
$config = $this->mergeCustomProperties($config);
$tca['config'] = array_replace($tca['config'] ?? [], $config);
return $tca;
Expand Down
1 change: 1 addition & 0 deletions Classes/Generator/TcaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ protected static function getNonOverridableOptions(): array
'option' => 'format',
],
'l10n_mode',
'dbFieldLength',
];
}

Expand Down
9 changes: 9 additions & 0 deletions Documentation/YamlReference/FieldTypes/Select/Index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ Settings
:yaml:`renderType` is set to :yaml:`selectSingle`, a relationship
:yaml:`manyToOne` is automatically inferred.

.. confval:: dbFieldLength
:name: select-dbFieldLength
:required: false
:type: int
:default: 255

This option can be used to set an alternative size for the database
:sql:`varchar` column. The default size is `255`.

.. confval:: allowedCustomProperties
:name: select-allowedCustomProperties
:required: false
Expand Down
3 changes: 3 additions & 0 deletions Tests/Unit/FieldTypes/SelectFieldTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'itemsProcConfig' => [
'foo' => 'bar',
],
'dbFieldLength' => 10,
],
'expectedTca' => [
'label' => 'foo',
Expand Down Expand Up @@ -136,6 +137,7 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'treeConfig' => [
'foo' => 'bar',
],
'dbFieldLength' => 10,
'itemsProcConfig' => [
'foo' => 'bar',
],
Expand Down Expand Up @@ -180,6 +182,7 @@ public static function getTcaReturnsExpectedTcaDataProvider(): iterable
'sortItems' => [],
'appearance' => [],
'treeConfig' => [],
'dbFieldLength' => 0,
],
'expectedTca' => [
'config' => [
Expand Down

0 comments on commit 0e12f73

Please sign in to comment.