From 68130cc664fb34f3d3a13041d5b561ddf99b3a81 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/4] 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 a847da6270247d0a60fa8994d79f8ef06de6a973 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/4] 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 05e1281cba4f3fca886f482e4da2ddef0662a7c9 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/4] 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 2fc03769bf8849373af2766b2a7bdb682459a540 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/4] 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