|
5 | 5 | namespace Themes\Rozier\Forms;
|
6 | 6 |
|
7 | 7 | use RZ\Roadiz\CoreBundle\Entity\CustomFormField;
|
| 8 | +use RZ\Roadiz\CoreBundle\Form\DataListTextType; |
8 | 9 | use RZ\Roadiz\CoreBundle\Form\MarkdownType;
|
| 10 | +use RZ\Roadiz\CoreBundle\Repository\CustomFormFieldRepository; |
9 | 11 | use Symfony\Component\Form\AbstractType;
|
10 | 12 | use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
|
11 | 13 | use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
|
16 | 18 |
|
17 | 19 | class CustomFormFieldType extends AbstractType
|
18 | 20 | {
|
| 21 | + public function __construct( |
| 22 | + private readonly CustomFormFieldRepository $customFormFieldRepository |
| 23 | + ) { |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * @param CustomFormField $field |
| 28 | + * @return string[] |
| 29 | + */ |
| 30 | + protected function getAllGroupsNames(CustomFormField $field): array |
| 31 | + { |
| 32 | + return $this->customFormFieldRepository->findDistinctGroupNamesInCustomForm($field->getCustomForm()); |
| 33 | + } |
| 34 | + |
19 | 35 | public function buildForm(FormBuilderInterface $builder, array $options): void
|
20 | 36 | {
|
21 | 37 | $builder->add('label', TextType::class, [
|
@@ -57,10 +73,51 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
|
57 | 73 | ],
|
58 | 74 | ]
|
59 | 75 | )
|
60 |
| - ->add('groupName', TextType::class, [ |
| 76 | + ->add('groupName', DataListTextType::class, [ |
61 | 77 | 'label' => 'groupName',
|
62 | 78 | 'required' => false,
|
63 | 79 | 'help' => 'use_the_same_group_names_over_fields_to_gather_them_in_tabs',
|
| 80 | + 'list' => $this->getAllGroupsNames($builder->getData()), |
| 81 | + 'listName' => 'group-names', |
| 82 | + 'attr' => [ |
| 83 | + 'autocomplete' => 'off', |
| 84 | + ], |
| 85 | + ]) |
| 86 | + ->add('autocomplete', ChoiceType::class, [ |
| 87 | + 'label' => 'customForm.autocomplete', |
| 88 | + 'help' => 'customForm.autocomplete.help', |
| 89 | + 'choices' => [ |
| 90 | + 'off', |
| 91 | + 'name', |
| 92 | + 'honorific-prefix', |
| 93 | + 'honorific-suffix', |
| 94 | + 'given-name', |
| 95 | + 'additional-name', |
| 96 | + 'family-name', |
| 97 | + 'nickname', |
| 98 | + 'email', |
| 99 | + 'username', |
| 100 | + 'organization-title', |
| 101 | + 'organization', |
| 102 | + 'street-address', |
| 103 | + 'country', |
| 104 | + 'country-name', |
| 105 | + 'postal-code', |
| 106 | + 'bday', |
| 107 | + 'bday-day', |
| 108 | + 'bday-month', |
| 109 | + 'bday-year', |
| 110 | + 'sex', |
| 111 | + 'tel', |
| 112 | + 'tel-national', |
| 113 | + 'url', |
| 114 | + 'photo', |
| 115 | + ], |
| 116 | + 'placeholder' => 'autocomplete.no_autocomplete', |
| 117 | + 'choice_label' => function ($choice, $key, $value) { |
| 118 | + return 'autocomplete.' . $value; |
| 119 | + }, |
| 120 | + 'required' => false, |
64 | 121 | ]);
|
65 | 122 | }
|
66 | 123 |
|
|
0 commit comments