From 37ad27308ec4ca888b489a8ebcf652d1488da97b Mon Sep 17 00:00:00 2001
From: Martin Anderson-Clutz <46883-mandclu@users.noreply.drupalcode.org>
Date: Mon, 26 May 2025 17:40:19 +0000
Subject: [PATCH 1/5] Add machine name constraints

---
 config/schema/webform.block.schema.yml          | 4 ++++
 config/schema/webform.entity.webform.schema.yml | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/config/schema/webform.block.schema.yml b/config/schema/webform.block.schema.yml
index 58150e0f5e..b12a92fd8e 100644
--- a/config/schema/webform.block.schema.yml
+++ b/config/schema/webform.block.schema.yml
@@ -5,6 +5,10 @@ block.settings.webform_block:
     webform_id:
       type: string
       label: Webform
+      constraints:
+        Regex:
+          pattern: '/^[a-z0-9_]+$/'
+          message: "The %value machine name is not valid."
     default_data:
       type: text
       label: 'Default webform submission data'
diff --git a/config/schema/webform.entity.webform.schema.yml b/config/schema/webform.entity.webform.schema.yml
index c917ee3626..fc3cb0d919 100644
--- a/config/schema/webform.entity.webform.schema.yml
+++ b/config/schema/webform.entity.webform.schema.yml
@@ -26,6 +26,10 @@
     id:
       type: string
       label: 'Machine name'
+      constraints:
+        Regex:
+          pattern: '/^[a-z0-9_]+$/'
+          message: "The %value machine name is not valid."
     title:
       type: label
       label: Title
-- 
GitLab


From 63d4a0739af95309c08d7e41d778dda90c938599 Mon Sep 17 00:00:00 2001
From: Martin Anderson-Clutz <46883-mandclu@users.noreply.drupalcode.org>
Date: Tue, 27 May 2025 13:34:17 +0000
Subject: [PATCH 2/5] Add FullyValidatable

---
 config/schema/webform.block.schema.yml | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/config/schema/webform.block.schema.yml b/config/schema/webform.block.schema.yml
index b12a92fd8e..d81a48d339 100644
--- a/config/schema/webform.block.schema.yml
+++ b/config/schema/webform.block.schema.yml
@@ -1,6 +1,8 @@
 block.settings.webform_block:
   type: block_settings
   label: 'Webforms block'
+  constraints:
+    FullyValidatable: ~
   mapping:
     webform_id:
       type: string
-- 
GitLab


From 693b78f4c5059c3959ea232ae7824582f76e5eed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?=
 <15738-goba@users.noreply.drupalcode.org>
Date: Tue, 27 May 2025 17:03:11 +0000
Subject: [PATCH 3/5] Making fully validatable that way did not work for me but
 there was a missing ID key in the mapping that was in the data. This way all
 there was to the block config from webform was validatable for me.

---
 config/schema/webform.block.schema.yml | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/config/schema/webform.block.schema.yml b/config/schema/webform.block.schema.yml
index d81a48d339..4795bc2544 100644
--- a/config/schema/webform.block.schema.yml
+++ b/config/schema/webform.block.schema.yml
@@ -1,9 +1,14 @@
 block.settings.webform_block:
   type: block_settings
   label: 'Webforms block'
-  constraints:
-    FullyValidatable: ~
   mapping:
+    id:
+      type: string
+      label: Identifier
+      constraints:
+        Regex:
+          pattern: '/^[a-z0-9_]+$/'
+          message: "The %value machine name is not valid."
     webform_id:
       type: string
       label: Webform
-- 
GitLab


From 7f288af78178e389e0895d215fc3358b7c4732ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?=
 <15738-goba@users.noreply.drupalcode.org>
Date: Wed, 25 Jun 2025 15:25:44 +0000
Subject: [PATCH 4/5] Make webform picker in block a select list, which does
 work in XB unlike the autocomplete. Also this means the user does not need to
 remember the exact names of their forms :)

---
 src/Plugin/Block/WebformBlock.php | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/src/Plugin/Block/WebformBlock.php b/src/Plugin/Block/WebformBlock.php
index 247b9aa059..cb6552f0e6 100644
--- a/src/Plugin/Block/WebformBlock.php
+++ b/src/Plugin/Block/WebformBlock.php
@@ -104,10 +104,11 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
 
     $form['#attributes'] = ['class' => ['webform-block-settings-tray-form']];
     $form['webform_id'] = [
-      '#type' => 'entity_autocomplete',
+      '#type' => 'select',
+      '#options' => $this->getWebFormOptions(),
+      '#empty_option' => $this->t('- Select -'),
       '#title' => $this->t('Webform', [], ['context' => 'form']),
       '#description' => $this->t('Select the webform that you would like to display in this block.'),
-      '#target_type' => 'webform',
       '#required' => TRUE,
       '#default_value' => $this->getWebform(),
     ];
@@ -259,4 +260,16 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
     return $this->entityTypeManager->getStorage('webform')->load($this->configuration['webform_id']);
   }
 
+  /**
+   * Build potential webform options for a select field.
+   */
+  protected function getWebFormOptions() {
+    $options = [];
+    $webforms = $this->entityTypeManager->getStorage('webform')->loadMultiple();
+    foreach ($webforms as $webform) {
+      $options[$webform->id()] = $webform->label();
+    }
+    return $options;
+  }
+
 }
-- 
GitLab


From 5ea597f12afd63fec5e067d5c68c557b33b72513 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?G=C3=A1bor=20Hojtsy?=
 <15738-goba@users.noreply.drupalcode.org>
Date: Mon, 7 Jul 2025 14:00:58 +0000
Subject: [PATCH 5/5] Retract the select box workaround for an XB autocomplete
 bug to make this move :) This should not be required anyway, assuming the
 autocomplete works in XB.

---
 src/Plugin/Block/WebformBlock.php | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/src/Plugin/Block/WebformBlock.php b/src/Plugin/Block/WebformBlock.php
index cb6552f0e6..247b9aa059 100644
--- a/src/Plugin/Block/WebformBlock.php
+++ b/src/Plugin/Block/WebformBlock.php
@@ -104,11 +104,10 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
 
     $form['#attributes'] = ['class' => ['webform-block-settings-tray-form']];
     $form['webform_id'] = [
-      '#type' => 'select',
-      '#options' => $this->getWebFormOptions(),
-      '#empty_option' => $this->t('- Select -'),
+      '#type' => 'entity_autocomplete',
       '#title' => $this->t('Webform', [], ['context' => 'form']),
       '#description' => $this->t('Select the webform that you would like to display in this block.'),
+      '#target_type' => 'webform',
       '#required' => TRUE,
       '#default_value' => $this->getWebform(),
     ];
@@ -260,16 +259,4 @@ class WebformBlock extends BlockBase implements ContainerFactoryPluginInterface
     return $this->entityTypeManager->getStorage('webform')->load($this->configuration['webform_id']);
   }
 
-  /**
-   * Build potential webform options for a select field.
-   */
-  protected function getWebFormOptions() {
-    $options = [];
-    $webforms = $this->entityTypeManager->getStorage('webform')->loadMultiple();
-    foreach ($webforms as $webform) {
-      $options[$webform->id()] = $webform->label();
-    }
-    return $options;
-  }
-
 }
-- 
GitLab