1212namespace Evoweb \Sessionplaner \Domain \Factory ;
1313
1414use Evoweb \Sessionplaner \Domain \Finisher \SuggestFormFinisher ;
15+ use Evoweb \Sessionplaner \Domain \Repository \TagRepository ;
1516use Evoweb \Sessionplaner \Enum \SessionLevelEnum ;
1617use Evoweb \Sessionplaner \Enum \SessionRequestTypeEnum ;
1718use Evoweb \Sessionplaner \Enum \SessionTypeEnum ;
@@ -35,12 +36,16 @@ class SuggestFormFactory extends AbstractFormFactory
3536
3637 protected ConfigurationManagerInterface $ configurationManager ;
3738
39+ protected TagRepository $ tagRepository ;
40+
3841 public function __construct (
3942 ConfigurationManagerInterface $ configurationManager ,
40- ConfigurationService $ formConfigurationService
43+ ConfigurationService $ formConfigurationService ,
44+ TagRepository $ tagRepository
4145 ) {
4246 $ this ->configurationManager = $ configurationManager ;
4347 $ this ->formConfigurationService = $ formConfigurationService ;
48+ $ this ->tagRepository = $ tagRepository ;
4449 }
4550
4651 public function build (array $ configuration , string $ prototypeName = null ): FormDefinition
@@ -141,6 +146,30 @@ public function build(array $configuration, string $prototypeName = null): FormD
141146 $ typeField ->setProperty ('options ' , $ typeFieldOptions );
142147 }
143148
149+ if ($ settings ['suggest ' ]['fields ' ]['tag ' ]['enable ' ]) {
150+ $ tags = $ this ->tagRepository ->findBy (['suggestFormOption ' => true ]);
151+ if ($ tags ->current ()) {
152+ /** @var GenericFormElement $tagField */
153+ $ tagField = $ sessionInformation ->createElement ('tag ' , 'SingleSelect ' );
154+ $ tagField ->setLabel ($ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['label ' ]));
155+ $ tagField ->setProperty (
156+ 'elementDescription ' ,
157+ $ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['description ' ])
158+ );
159+ $ tagField ->addValidator (GeneralUtility::makeInstance (NotEmptyValidator::class));
160+ $ tagFieldOptions = [];
161+ foreach ($ tags as $ tag ) {
162+ $ tagFieldOptions [$ tag ->getUid ()] = $ tag ->getLabel ();
163+ }
164+ $ prependOptionLabel = ' ' ;
165+ if (!empty ($ settings ['suggest ' ]['fields ' ]['tag ' ]['prependOptionLabel ' ])) {
166+ $ prependOptionLabel = $ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['prependOptionLabel ' ]);
167+ }
168+ $ tagField ->setProperty ('prependOptionLabel ' , $ prependOptionLabel );
169+ $ tagField ->setProperty ('options ' , $ tagFieldOptions );
170+ }
171+ }
172+
144173 /** @var GenericFormElement $titleField */
145174 $ titleField = $ sessionInformation ->createElement ('title ' , 'Text ' );
146175 $ titleField ->setLabel ($ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['title ' ]['label ' ]));
0 commit comments