@@ -16,7 +16,6 @@ class ValidCollection implements PropertyRule
1616 public function __construct (
1717 private int $ maxCount = 0 ,
1818 private int $ minCount = 1 ,
19- private bool $ uniqueIds = false ,
2019 ) {}
2120
2221 public function check (Component $ component , string $ field , mixed $ value ): void
@@ -50,44 +49,5 @@ public function check(Component $component, string $field, mixed $value): void
5049 [$ field , $ component ->type ->value , $ this ->maxCount ],
5150 );
5251 }
53-
54- if (!$ this ->uniqueIds ) {
55- return ;
56- }
57-
58- $ uniqueIds = [];
59- foreach ($ collection as $ item ) {
60- ['field ' => $ idField , 'value ' => $ idValue ] = $ this ->extractId ($ item );
61- if (!empty ($ idValue )) {
62- if (in_array ($ idValue , $ uniqueIds , true )) {
63- throw new ValidationException (
64- 'The "%s" field of a valid "%s" component must NOT have any items with duplicate "%s"s ' ,
65- [$ field , $ component ->type ->value , $ idField ],
66- );
67- } else {
68- $ uniqueIds [] = $ idValue ;
69- }
70- }
71- }
72- }
73-
74- /**
75- * @return array{field: ?string, value: ?string}
76- */
77- private function extractId (mixed $ item ): array
78- {
79- if (!$ item instanceof Component) {
80- return ['field ' => null , 'value ' => null ];
81- }
82-
83- if (isset ($ item ->blockId )) {
84- return ['field ' => 'block_id ' , 'value ' => $ item ->blockId ];
85- }
86-
87- if (isset ($ item ->actionId )) {
88- return ['field ' => 'action_id ' , 'value ' => $ item ->actionId ];
89- }
90-
91- return ['field ' => null , 'value ' => null ];
9252 }
9353}
0 commit comments