44
55use Drupal \Core \Form \FormStateInterface ;
66use Drupal \Core \Link ;
7+ use Drupal \Core \Lock \NullLockBackend ;
78use Drupal \Core \StringTranslation \StringTranslationTrait ;
89use Drupal \os2forms_fordelingskomponent \Helper \FordelingskomponentHelper ;
910use Drupal \os2forms_fordelingskomponent \Helper \WebformHelperSF2900 ;
@@ -29,6 +30,7 @@ final class WebformHandlerSF2900 extends WebformHandlerBase {
2930
3031 public const string ID = 'os2forms_fordelingskomponent_sf2900 ' ;
3132
33+ public const string SECTION_SF2900 = 'sf2900 ' ;
3234 public const string ATTACHMENT_ELEMENT = 'attachment_element ' ;
3335
3436 /**
@@ -50,50 +52,81 @@ public static function create(ContainerInterface $container, array $configuratio
5052 * {@inheritdoc}
5153 */
5254 public function buildConfigurationForm (array $ form , FormStateInterface $ form_state ) {
53- $ form [FordelingskomponentHelper::KLE_EMNE ] = [
55+ $ form [static ::SECTION_SF2900 ] = [
56+ '#type ' => 'fieldset ' ,
57+ '#title ' => $ this ->t ('Fordelingskomponent ' ),
58+ '#tree ' => true ,
59+ ];
60+
61+ $ configuration = $ this ->configuration [static ::SECTION_SF2900 ] ?? NULL ;
62+
63+ $ form [static ::SECTION_SF2900 ][FordelingskomponentHelper::KLE_EMNE ] = [
5464 '#title ' => $ this ->t ('KLE-emne ' ),
5565 '#type ' => 'textfield ' ,
56- '#default_value ' => $ this -> configuration [FordelingskomponentHelper::KLE_EMNE ],
66+ '#default_value ' => $ configuration [FordelingskomponentHelper::KLE_EMNE ] ?? NULL ,
5767 '#required ' => TRUE ,
5868 '#attributes ' => [
5969 'pattern ' => FordelingskomponentHelper::KLE_EMNE_PATTERN ,
6070 ],
6171 '#description ' => $ this ->t ('KLE-emne (format: dd.dd.dd) ' ),
6272 ];
63- $ form [FordelingskomponentHelper::HANDLING_FACET ] = [
73+
74+ $ form [static ::SECTION_SF2900 ][FordelingskomponentHelper::HANDLING_FACET ] = [
6475 '#title ' => $ this ->t ('Handling-facet ' ),
6576 '#type ' => 'textfield ' ,
66- '#default_value ' => $ this -> configuration [FordelingskomponentHelper::HANDLING_FACET ],
77+ '#default_value ' => $ configuration [FordelingskomponentHelper::HANDLING_FACET ] ?? NULL ,
6778 '#attributes ' => [
6879 'pattern ' => FordelingskomponentHelper::HANDLING_FACET_PATTERN ,
6980 ],
7081 ];
7182
7283 $ availableElements = $ this ->getAttachmentElements ();
73- $ form [static ::ATTACHMENT_ELEMENT ] = [
84+ $ form [static ::SECTION_SF2900 ][ static :: ATTACHMENT_ELEMENT ] = [
7485 '#type ' => 'select ' ,
7586 '#title ' => $ this ->t ('Element that contains the document to send ' ),
87+ '#default_value ' => $ configuration [static ::ATTACHMENT_ELEMENT ] ?? NULL ,
7688 '#required ' => TRUE ,
77- '#default_value ' => $ this ->configuration [static ::ATTACHMENT_ELEMENT ] ?? NULL ,
7889 '#options ' => $ availableElements ,
7990 ];
8091
81- // @todo Change the autogenerated stub
82- return parent ::buildConfigurationForm ($ form , $ form_state );
92+ $ form [static ::SECTION_SF2900 ][FordelingskomponentHelper::BRUGERVENDT_NOEGLE ] = [
93+ '#title ' => $ this ->t ('Brugervendt nøgle ' ),
94+ '#type ' => 'textfield ' ,
95+ '#default_value ' => $ configuration [FordelingskomponentHelper::BRUGERVENDT_NOEGLE ] ?? null ,
96+ '#required ' => true ,
97+ '#description ' => 'WHAT IS THIS?! ' ,
98+ ];
99+
100+ $ form [static ::SECTION_SF2900 ][FordelingskomponentHelper::TITEL ] = [
101+ '#title ' => $ this ->t ('Titel ' ),
102+ '#type ' => 'textfield ' ,
103+ '#default_value ' => $ configuration [FordelingskomponentHelper::TITEL ] ?? null ,
104+ '#required ' => true ,
105+ ];
106+
107+ $ form [static ::SECTION_SF2900 ][FordelingskomponentHelper::BESKRIVELSE ] = [
108+ '#title ' => $ this ->t ('Beskrivelse ' ),
109+ '#type ' => 'textarea ' ,
110+ '#default_value ' => $ configuration [FordelingskomponentHelper::BESKRIVELSE ] ?? NULL ,
111+ '#required ' => TRUE ,
112+ ];
113+
114+ return $ this ->setSettingsParents ($ form );
83115 }
84116
85117 /**
86118 * {@inheritdoc}
87119 */
88120 public function validateConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
89- $ kleEMne = $ form_state ->getValue (FordelingskomponentHelper::KLE_EMNE );
121+ $ values = $ form_state ->getValue (static ::SECTION_SF2900 );
122+ $ kleEMne = $ values [FordelingskomponentHelper::KLE_EMNE ];
90123 if (!preg_match ('/ ' . FordelingskomponentHelper::KLE_EMNE_PATTERN . '/ ' , (string ) $ kleEMne )) {
91- $ form_state ->setErrorByName (FordelingskomponentHelper::KLE_EMNE , $ this ->t ('Invalid KLE-emne: %kle_emne. ' , ['%kle_emne ' => $ kleEMne ]));
124+ $ form_state ->setErrorByName (static :: SECTION_SF2900 . ' ][ ' . FordelingskomponentHelper::KLE_EMNE , $ this ->t ('Invalid KLE-emne: %kle_emne. ' , ['%kle_emne ' => $ kleEMne ]));
92125 }
93126
94- $ handling_facet = $ form_state -> getValue ( FordelingskomponentHelper::HANDLING_FACET ) ;
127+ $ handling_facet = $ values [ FordelingskomponentHelper::HANDLING_FACET ] ;
95128 if (!empty ($ handling_facet ) && !preg_match ('/ ' . FordelingskomponentHelper::HANDLING_FACET_PATTERN . '/ ' , (string ) $ handling_facet )) {
96- $ form_state ->setErrorByName (FordelingskomponentHelper::HANDLING_FACET ,
129+ $ form_state ->setErrorByName (static :: SECTION_SF2900 . ' ][ ' . FordelingskomponentHelper::HANDLING_FACET ,
97130 $ this ->t ('Invalid Handling-facet: %handling_facet. ' , ['%handling_facet ' => $ handling_facet ]));
98131 }
99132
@@ -106,10 +139,7 @@ public function validateConfigurationForm(array &$form, FormStateInterface $form
106139 public function submitConfigurationForm (array &$ form , FormStateInterface $ form_state ) {
107140 parent ::submitConfigurationForm ($ form , $ form_state );
108141
109- $ this ->configuration [FordelingskomponentHelper::KLE_EMNE ] = $ form_state ->getValue (FordelingskomponentHelper::KLE_EMNE );
110- $ this ->configuration [FordelingskomponentHelper::HANDLING_FACET ] = $ form_state ->getValue (FordelingskomponentHelper::HANDLING_FACET );
111- $ this ->configuration [static ::ATTACHMENT_ELEMENT ] = $ form_state ->getValue (static ::ATTACHMENT_ELEMENT );
112-
142+ $ this ->configuration [static ::SECTION_SF2900 ] = $ form_state ->getValue (static ::SECTION_SF2900 );
113143 }
114144
115145 /**
@@ -121,7 +151,7 @@ public function postSave(WebformSubmissionInterface $webform_submission, $update
121151 return ;
122152 }
123153
124- $ this ->helper ->createJob ($ webform_submission , $ this ->configuration );
154+ $ this ->helper ->createJob ($ webform_submission , $ this ->configuration [ static :: SECTION_SF2900 ] );
125155 }
126156
127157 /**
0 commit comments