33namespace Drupal \os2forms_digital_post \Plugin \WebformHandler ;
44
55use Drupal \Core \Form \FormStateInterface ;
6+ use Drupal \os2forms \Plugin \WebformHandler \OS2FormsHandlerInterface ;
67use Drupal \os2forms_digital_post \Helper \MeMoHelper ;
78use Drupal \os2forms_digital_post \Helper \WebformHelperSF1601 ;
89use Drupal \webform \Plugin \WebformHandlerBase ;
2324 * submission = \Drupal\webform\Plugin\WebformHandlerInterface::SUBMISSION_REQUIRED,
2425 * )
2526 */
26- final class WebformHandlerSF1601 extends WebformHandlerBase {
27+ final class WebformHandlerSF1601 extends WebformHandlerBase implements OS2FormsHandlerInterface {
2728 public const MEMO_MESSAGE = 'memo_message ' ;
2829 public const MEMO_ACTIONS = 'memo_actions ' ;
2930 public const TYPE = 'type ' ;
@@ -110,6 +111,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
110111 '#required ' => TRUE ,
111112 '#default_value ' => $ this ->configuration [self ::MEMO_MESSAGE ][static ::RECIPIENT_ELEMENT ] ?? NULL ,
112113 '#options ' => $ availableElements ,
114+ '#empty_option ' => $ this ->t ('- Select - ' ),
113115 ];
114116
115117 $ availableElements = $ this ->getAttachmentElements ();
@@ -119,6 +121,7 @@ public function buildConfigurationForm(array $form, FormStateInterface $formStat
119121 '#required ' => TRUE ,
120122 '#default_value ' => $ this ->configuration [self ::MEMO_MESSAGE ][static ::ATTACHMENT_ELEMENT ] ?? NULL ,
121123 '#options ' => $ availableElements ,
124+ '#empty_option ' => $ this ->t ('- Select - ' ),
122125 ];
123126
124127 $ form [self ::MEMO_MESSAGE ][self ::SENDER_LABEL ] = [
@@ -264,6 +267,37 @@ static function (array $element) use ($elementTypes) {
264267 }, $ elements );
265268 }
266269
270+ /**
271+ * {@inheritdoc}
272+ *
273+ * @phpstan-return array<int, mixed>
274+ */
275+ public function validateConfiguration (): array {
276+ $ problems = [];
277+
278+ $ recipientElement = $ this ->configuration [self ::MEMO_MESSAGE ][static ::RECIPIENT_ELEMENT ] ?? NULL ;
279+ if (NULL === $ recipientElement || '' === $ recipientElement ) {
280+ $ problems [] = $ this ->t ('No recipient element is configured. ' );
281+ }
282+ elseif (!isset ($ this ->getRecipientElements ()[$ recipientElement ])) {
283+ $ problems [] = $ this ->t ('The recipient element (%element) does not exist or does not have a supported type. ' , [
284+ '%element ' => $ recipientElement ,
285+ ]);
286+ }
287+
288+ $ attachmentElement = $ this ->configuration [self ::MEMO_MESSAGE ][static ::ATTACHMENT_ELEMENT ] ?? NULL ;
289+ if (NULL === $ attachmentElement || '' === $ attachmentElement ) {
290+ $ problems [] = $ this ->t ('No attachment element is configured. ' );
291+ }
292+ elseif (!isset ($ this ->getAttachmentElements ()[$ attachmentElement ])) {
293+ $ problems [] = $ this ->t ('The attachment element (%element) does not exist or does not have a supported type. ' , [
294+ '%element ' => $ attachmentElement ,
295+ ]);
296+ }
297+
298+ return $ problems ;
299+ }
300+
267301 /**
268302 * {@inheritdoc}
269303 *
0 commit comments