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,28 @@ public function build(array $configuration, string $prototypeName = null): FormD
141146 $ typeField ->setProperty ('options ' , $ typeFieldOptions );
142147 }
143148
149+ $ tags = $ this ->tagRepository ->findBy (['suggestFormOption ' => true ]);
150+ if ($ settings ['suggest ' ]['fields ' ]['tag ' ]['enable ' ] && $ tags ->current ()) {
151+ /** @var GenericFormElement $tagField */
152+ $ tagField = $ sessionInformation ->createElement ('tag ' , 'SingleSelect ' );
153+ $ tagField ->setLabel ($ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['label ' ]));
154+ $ tagField ->setProperty (
155+ 'elementDescription ' ,
156+ $ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['description ' ])
157+ );
158+ $ tagField ->addValidator (GeneralUtility::makeInstance (NotEmptyValidator::class));
159+ $ tagFieldOptions = [];
160+ foreach ($ tags as $ tag ) {
161+ $ tagFieldOptions [$ tag ->getUid ()] = $ tag ->getLabel ();
162+ }
163+ $ prependOptionLabel = ' ' ;
164+ if (!empty ($ settings ['suggest ' ]['fields ' ]['tag ' ]['prependOptionLabel ' ])) {
165+ $ prependOptionLabel = $ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['tag ' ]['prependOptionLabel ' ]);
166+ }
167+ $ tagField ->setProperty ('prependOptionLabel ' , $ prependOptionLabel );
168+ $ tagField ->setProperty ('options ' , $ tagFieldOptions );
169+ }
170+
144171 /** @var GenericFormElement $titleField */
145172 $ titleField = $ sessionInformation ->createElement ('title ' , 'Text ' );
146173 $ titleField ->setLabel ($ this ->getLocalizedLabel ($ settings ['suggest ' ]['fields ' ]['title ' ]['label ' ]));
0 commit comments