Skip to content

Commit 5b905b3

Browse files
committed
IBX-9060: Updated FormFactory to improve naming strategies and ensure consistency across form types.
1 parent 4d8ced0 commit 5b905b3

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

src/lib/Form/Factory/FormFactory.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ public function updateVisibilityLocation(
457457
?LocationUpdateVisibilityData $data = null,
458458
?string $name = null
459459
): FormInterface {
460-
$name = $name ?: StringUtil::fqcnToBlockPrefix(LocationUpdateVisibilityType::class);
460+
$name = $name ?: StringUtil::fqcnToBlockPrefix(LocationUpdateVisibilityData::class);
461461

462462
if (!is_string($name) || $name === '') {
463463
throw new InvalidArgumentException(
@@ -797,14 +797,10 @@ public function updatePolicy(
797797
PolicyUpdateData $data,
798798
?string $name = null
799799
): FormInterface {
800-
$name = $name ?: StringUtil::fqcnToBlockPrefix(PolicyUpdateType::class);
801-
802-
if (!is_string($name) || $name === '') {
803-
throw new InvalidArgumentException(
804-
'name',
805-
'The form name must be a non-empty string.'
806-
);
807-
}
800+
$name = $name ?: sprintf(
801+
'update-policy-%s',
802+
hash('sha256', implode('/', $data->getPolicy()))
803+
);
808804

809805
return $this->formFactory->createNamed($name, PolicyUpdateType::class, $data);
810806
}
@@ -813,14 +809,10 @@ public function deletePolicy(
813809
PolicyDeleteData $data,
814810
?string $name = null
815811
): FormInterface {
816-
$name = $name ?: StringUtil::fqcnToBlockPrefix(PolicyDeleteType::class);
817-
818-
if (!is_string($name) || $name === '') {
819-
throw new InvalidArgumentException(
820-
'name',
821-
'The form name must be a non-empty string.'
822-
);
823-
}
812+
$name = $name ?: sprintf(
813+
'delete-policy-%s',
814+
hash('sha256', implode('/', $data->getPolicy()))
815+
);
824816

825817
return $this->formFactory->createNamed($name, PolicyDeleteType::class, $data);
826818
}
@@ -849,7 +841,7 @@ public function createSearchForm(
849841
?string $name = null,
850842
array $options = []
851843
): FormInterface {
852-
$name = $name ?: StringUtil::fqcnToBlockPrefix(SearchType::class);
844+
$name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
853845

854846
if (!is_string($name) || $name === '') {
855847
throw new InvalidArgumentException(
@@ -866,7 +858,7 @@ public function createUrlListForm(
866858
?string $name = null,
867859
array $options = []
868860
): FormInterface {
869-
$name = $name ?: StringUtil::fqcnToBlockPrefix(URLListType::class);
861+
$name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
870862

871863
if (!is_string($name) || $name === '') {
872864
throw new InvalidArgumentException(
@@ -883,7 +875,7 @@ public function createUrlEditForm(
883875
?string $name = null,
884876
array $options = []
885877
): FormInterface {
886-
$name = $name ?: StringUtil::fqcnToBlockPrefix(URLEditType::class);
878+
$name = $name ?: StringUtil::fqcnToBlockPrefix(SearchData::class);
887879

888880
if (!is_string($name) || $name === '') {
889881
throw new InvalidArgumentException(

0 commit comments

Comments
 (0)