Skip to content

Commit

Permalink
fix: prevent double required config key in TCA (#3451)
Browse files Browse the repository at this point in the history
Resolves: #3450
  • Loading branch information
helsner authored Aug 9, 2023
1 parent 331a7d4 commit 38f1a9f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 12 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,8 @@
"branch-alias": {
"dev-main": "1.0-dev"
}
},
"conflict": {
"phpstan/phpstan": "1.10.28"
}
}
5 changes: 3 additions & 2 deletions src/Rector/v12/v0/tca/MigrateRequiredFlagRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void
$this->removeNode($evalArrayItem);
}

// If required config exists already, remove it to avoid duplicate array items
// If required config exists already do not add one again
$requiredItemToRemove = $this->extractArrayItemByKey($configArray, self::REQUIRED);
if ($requiredItemToRemove instanceof ArrayItem) {
$this->removeNode($requiredItemToRemove);
$this->hasAstBeenChanged = true;
return;
}

$configArray->items[] = new ArrayItem(new ConstFetch(new Name('true')), new String_(self::REQUIRED));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,39 @@ return [
'eval' => 'required',
],
],
'required_column2_copy' => [
'config' => [
'type' => 'foo',
'eval' => 'required',
],
],
'already_required_column' => [
'config' => [
'eval' => 'required',
'required' => true,
],
],
'contact_person_salutation' => [
'exclude' => 1,
'label' => 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang_db.xlf:tx_legacy_exntesion_domain_model_order.contact_person_salutation',
'config' => [
'type' => 'select',
'items' => [
['-', 0],
[
'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.1.label',
1,
],
[
'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.2.label',
2,
],
],
'size' => 1,
'eval' => 'required',
'maxitems' => 1,
],
],
],
];

Expand All @@ -43,8 +70,37 @@ return [
'required' => true,
],
],
'required_column2_copy' => [
'config' => [
'type' => 'foo',
'required' => true,
],
],
'already_required_column' => [
'config' => ['required' => true],
'config' => [
'required' => true,
],
],
'contact_person_salutation' => [
'exclude' => 1,
'label' => 'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang_db.xlf:tx_legacy_exntesion_domain_model_order.contact_person_salutation',
'config' => [
'type' => 'select',
'items' => [
['-', 0],
[
'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.1.label',
1,
],
[
'LLL:EXT:legacy_extensions/Resources/Private/Language/locallang.xlf:form.contactPersonSalutation.2.label',
2,
],
],
'size' => 1,
'maxitems' => 1,
'required' => true,
],
],
],
];
Expand Down

0 comments on commit 38f1a9f

Please sign in to comment.