1919final class SettingsForm extends FormBase {
2020 use StringTranslationTrait;
2121
22+ public const TEST_MODE = 'test_mode ' ;
23+ public const SENDER = 'sender ' ;
24+ public const CERTIFICATE = 'certificate ' ;
25+ public const PROCESSING = 'processing ' ;
26+
2227 /**
2328 * The queue storage.
2429 *
@@ -63,15 +68,15 @@ public function getFormId() {
6368 * @phpstan-param array<string, mixed> $form
6469 * @phpstan-return array<string, mixed>
6570 */
66- public function buildForm (array $ form , FormStateInterface $ form_state ) {
67- $ form [' test_mode ' ] = [
71+ public function buildForm (array $ form , FormStateInterface $ form_state ): array {
72+ $ form [self :: TEST_MODE ] = [
6873 '#type ' => 'checkbox ' ,
6974 '#title ' => $ this ->t ('Test mode ' ),
7075 '#default_value ' => $ this ->settings ->getTestMode (),
7176 ];
7277
7378 $ sender = $ this ->settings ->getSender ();
74- $ form [' sender ' ] = [
79+ $ form [self :: SENDER ] = [
7580 '#type ' => 'fieldset ' ,
7681 '#title ' => $ this ->t ('Sender ' ),
7782 '#tree ' => TRUE ,
@@ -102,24 +107,24 @@ public function buildForm(array $form, FormStateInterface $form_state) {
102107 ];
103108
104109 $ certificate = $ this ->settings ->getCertificate ();
105- $ form [' certificate ' ] = [
110+ $ form [self :: CERTIFICATE ] = [
106111 '#type ' => 'fieldset ' ,
107112 '#title ' => $ this ->t ('Certificate ' ),
108113 '#tree ' => TRUE ,
109114
110- ' locator_type ' => [
115+ CertificateLocatorHelper:: LOCATOR_TYPE => [
111116 '#type ' => 'select ' ,
112117 '#title ' => $ this ->t ('Certificate locator type ' ),
113118 '#options ' => [
114119 CertificateLocatorHelper::LOCATOR_TYPE_KEY => $ this ->t ('Key ' ),
115120 CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT => $ this ->t ('Azure key vault ' ),
116121 CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM => $ this ->t ('File system ' ),
117122 ],
118- '#default_value ' => $ certificate [' locator_type ' ] ?? NULL ,
123+ '#default_value ' => $ certificate [CertificateLocatorHelper:: LOCATOR_TYPE ] ?? NULL ,
119124 ],
120125 ];
121126
122- $ form [' certificate ' ][CertificateLocatorHelper::LOCATOR_TYPE_KEY ] = [
127+ $ form [self :: CERTIFICATE ][CertificateLocatorHelper::LOCATOR_TYPE_KEY ] = [
123128 '#type ' => 'container ' ,
124129 '#states ' => [
125130 'visible ' => [':input[name="certificate[locator_type]"] ' => ['value ' => CertificateLocatorHelper::LOCATOR_TYPE_KEY ]],
@@ -138,7 +143,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
138143 ],
139144 ];
140145
141- $ form [' certificate ' ][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ] = [
146+ $ form [self :: CERTIFICATE ][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ] = [
142147 '#type ' => 'fieldset ' ,
143148 '#title ' => $ this ->t ('Azure key vault ' ),
144149 '#states ' => [
@@ -147,16 +152,16 @@ public function buildForm(array $form, FormStateInterface $form_state) {
147152 ];
148153
149154 $ settings = [
150- ' tenant_id ' => ['title ' => $ this ->t ('Tenant id ' )],
151- ' application_id ' => ['title ' => $ this ->t ('Application id ' )],
152- ' client_secret ' => ['title ' => $ this ->t ('Client secret ' )],
153- ' name ' => ['title ' => $ this ->t ('Name ' )],
154- ' secret ' => ['title ' => $ this ->t ('Secret ' )],
155- ' version ' => ['title ' => $ this ->t ('Version ' )],
155+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_TENANT_ID => ['title ' => $ this ->t ('Tenant id ' )],
156+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_APPLICATION_ID => ['title ' => $ this ->t ('Application id ' )],
157+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_CLIENT_SECRET => ['title ' => $ this ->t ('Client secret ' )],
158+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_NAME => ['title ' => $ this ->t ('Name ' )],
159+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_SECRET => ['title ' => $ this ->t ('Secret ' )],
160+ CertificateLocatorHelper:: LOCATOR_AZURE_KEY_VAULT_VERSION => ['title ' => $ this ->t ('Version ' )],
156161 ];
157162
158163 foreach ($ settings as $ key => $ info ) {
159- $ form [' certificate ' ][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ][$ key ] = [
164+ $ form [self :: CERTIFICATE ][CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ][$ key ] = [
160165 '#type ' => 'textfield ' ,
161166 '#title ' => $ info ['title ' ],
162167 '#default_value ' => $ certificate [CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ][$ key ] ?? NULL ,
@@ -166,7 +171,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
166171 ];
167172 }
168173
169- $ form [' certificate ' ][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM ] = [
174+ $ form [self :: CERTIFICATE ][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM ] = [
170175 '#type ' => 'fieldset ' ,
171176 '#title ' => $ this ->t ('File system ' ),
172177 '#states ' => [
@@ -183,29 +188,29 @@ public function buildForm(array $form, FormStateInterface $form_state) {
183188 ],
184189 ];
185190
186- $ form [' certificate ' ][ ' passphrase ' ] = [
191+ $ form [self :: CERTIFICATE ][CertificateLocatorHelper:: LOCATOR_PASSPHRASE ] = [
187192 '#type ' => 'textfield ' ,
188193 '#title ' => $ this ->t ('Passphrase ' ),
189- '#default_value ' => $ certificate ['passphrase ' ] ?? NULL ,
190-
194+ '#default_value ' => $ certificate [CertificateLocatorHelper::LOCATOR_PASSPHRASE ] ?? NULL ,
191195 '#states ' => [
192- 'visible ' => [':input[name="certificate[locator_type]"] ' => [
196+ 'visible ' => [
197+ ':input[name="certificate[locator_type]"] ' => [
193198 ['value ' => CertificateLocatorHelper::LOCATOR_TYPE_AZURE_KEY_VAULT ],
194199 ['value ' => CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM ],
195- ],
200+ ],
196201 ],
197202 ],
198203 ];
199204
200205 $ processing = $ this ->settings ->getProcessing ();
201- $ form [' processing ' ] = [
206+ $ form [self :: PROCESSING ] = [
202207 '#type ' => 'fieldset ' ,
203208 '#title ' => $ this ->t ('Processing ' ),
204209 '#tree ' => TRUE ,
205210 ];
206211
207212 $ defaultValue = $ processing ['queue ' ] ?? 'os2forms_digital_post ' ;
208- $ form [' processing ' ]['queue ' ] = [
213+ $ form [self :: PROCESSING ]['queue ' ] = [
209214 '#type ' => 'select ' ,
210215 '#title ' => $ this ->t ('Queue ' ),
211216 '#options ' => array_map (
@@ -247,8 +252,8 @@ public function validateForm(array &$form, FormStateInterface $formState): void
247252 }
248253
249254 $ values = $ formState ->getValues ();
250- if (CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM === $ values [' certificate ' ][ ' locator_type ' ]) {
251- $ path = $ values [' certificate ' ][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM ]['path ' ] ?? NULL ;
255+ if (CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM === $ values [self :: CERTIFICATE ][CertificateLocatorHelper:: LOCATOR_TYPE ]) {
256+ $ path = $ values [self :: CERTIFICATE ][CertificateLocatorHelper::LOCATOR_TYPE_FILE_SYSTEM ]['path ' ] ?? NULL ;
252257 if (!file_exists ($ path )) {
253258 $ formState ->setErrorByName ('certificate][file_system][path ' , $ this ->t ('Invalid certificate path: %path ' , ['%path ' => $ path ]));
254259 }
@@ -268,10 +273,11 @@ public function submitForm(array &$form, FormStateInterface $formState): void {
268273 }
269274
270275 try {
271- $ settings ['test_mode ' ] = (bool ) $ formState ->getValue ('test_mode ' );
272- $ settings ['sender ' ] = $ formState ->getValue ('sender ' );
273- $ settings ['certificate ' ] = $ formState ->getValue ('certificate ' );
274- $ settings ['processing ' ] = $ formState ->getValue ('processing ' );
276+ $ settings [self ::TEST_MODE ] = (bool ) $ formState ->getValue (self ::TEST_MODE );
277+ $ settings [self ::SENDER ] = $ formState ->getValue (self ::SENDER );
278+ $ settings [self ::CERTIFICATE ] = $ formState ->getValue (self ::CERTIFICATE );
279+ $ settings [self ::PROCESSING ] = $ formState ->getValue (self ::PROCESSING );
280+
275281 $ this ->settings ->setSettings ($ settings );
276282 $ this ->messenger ()->addStatus ($ this ->t ('Settings saved ' ));
277283 }
@@ -287,7 +293,7 @@ private function testCertificate(): void {
287293 try {
288294 $ certificateLocator = $ this ->certificateLocatorHelper ->getCertificateLocator ();
289295 $ certificateLocator ->getCertificates ();
290- $ this ->messenger ()->addStatus ($ this ->t ('Certificate succesfully tested ' ));
296+ $ this ->messenger ()->addStatus ($ this ->t ('Certificate successfully tested ' ));
291297 }
292298 catch (\Throwable $ throwable ) {
293299 $ message = $ this ->t ('Error testing certificate: %message ' , ['%message ' => $ throwable ->getMessage ()]);
0 commit comments