diff --git a/config/schema/webform.block.schema.yml b/config/schema/webform.block.schema.yml index 58150e0f5e4a457d19fb07ed14a17511dde8c586..4795bc2544b2fa395c9792e3649c4b8d70907c25 100644 --- a/config/schema/webform.block.schema.yml +++ b/config/schema/webform.block.schema.yml @@ -2,9 +2,20 @@ block.settings.webform_block: type: block_settings label: 'Webforms block' 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 + 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 c917ee3626087af49be099895d33f48ed4e064f1..fc3cb0d919f3e7863f5d14f2b1a9eea1898e40c7 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 diff --git a/src/Plugin/Block/WebformBlock.php b/src/Plugin/Block/WebformBlock.php index 247b9aa0592ae6b9b9afcfc69a0c9167285de320..cb6552f0e6d9bfda42e18801df8a673e9649e68f 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; + } + }