diff --git a/config/install/webform.settings.yml b/config/install/webform.settings.yml
index 14571626..7575903c 100644
--- a/config/install/webform.settings.yml
+++ b/config/install/webform.settings.yml
@@ -43,6 +43,8 @@ settings:
assets:
css: ''
javascript: ''
+handler:
+ excluded_handlers: { }
export:
exporter: delimited
delimiter: ','
@@ -59,6 +61,7 @@ export:
entity_reference_format: link
likert_answers_format: label
signature_format: status
+ excluded_exporters: { }
batch:
default_batch_export_size: 500
default_batch_update_size: 500
diff --git a/config/schema/webform.schema.yml b/config/schema/webform.schema.yml
index 5dee1046..aa3997a6 100644
--- a/config/schema/webform.schema.yml
+++ b/config/schema/webform.schema.yml
@@ -247,6 +247,16 @@ webform.settings:
composite_element_item_format:
type: string
label: 'Composite element item format'
+ excluded_exporters:
+ type: ignore
+ label: 'Excluded exporters'
+ handler:
+ type: mapping
+ label: 'Handler settings'
+ mapping:
+ excluded_handlers:
+ type: ignore
+ label: 'Excluded handlers'
batch:
type: mapping
label: 'Batch settings'
diff --git a/src/Controller/WebformPluginElementController.php b/src/Controller/WebformPluginElementController.php
index b0b08bb6..4b869566 100644
--- a/src/Controller/WebformPluginElementController.php
+++ b/src/Controller/WebformPluginElementController.php
@@ -3,6 +3,7 @@
namespace Drupal\webform\Controller;
use Drupal\Component\Render\FormattableMarkup;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Controller\ControllerBase;
@@ -18,6 +19,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformPluginElementController extends ControllerBase implements ContainerInjectionInterface {
/**
+ * The config factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* The module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
@@ -41,6 +49,8 @@ class WebformPluginElementController extends ControllerBase implements Container
/**
* Constructs a WebformPluginElementController object.
*
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The factory for configuration objects.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
* @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
@@ -48,7 +58,8 @@ class WebformPluginElementController extends ControllerBase implements Container
* @param \Drupal\webform\WebformElementManagerInterface $element_manager
* A webform element plugin manager.
*/
- public function __construct(ModuleHandlerInterface $module_handler, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager) {
+ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager) {
+ $this->configFactory = $config_factory;
$this->moduleHandler = $module_handler;
$this->elementInfo = $element_info;
$this->elementManager = $element_manager;
@@ -59,6 +70,7 @@ class WebformPluginElementController extends ControllerBase implements Container
*/
public static function create(ContainerInterface $container) {
return new static(
+ $container->get('config.factory'),
$container->get('module_handler'),
$container->get('plugin.manager.element_info'),
$container->get('plugin.manager.webform.element')
@@ -72,6 +84,8 @@ class WebformPluginElementController extends ControllerBase implements Container
$webform_form_element_rows = [];
$element_rows = [];
+ $excluded_types = $this->config('webform.settings')->get('elements.excluded_types');
+
$default_properties = [
// Element settings.
'title',
@@ -138,6 +152,7 @@ class WebformPluginElementController extends ControllerBase implements Container
$dependencies = $webform_element_plugin_definition['dependencies'];
$webform_info_definitions = [
+ 'excluded' => isset($excluded_types[$element_plugin_id]),
'input' => $webform_element->isInput($element),
'container' => $webform_element->isContainer($element),
'root' => $webform_element->isRoot(),
@@ -190,6 +205,7 @@ class WebformPluginElementController extends ControllerBase implements Container
'url' => $api_url,
];
}
+
$webform_form_element_rows[$element_plugin_id] = [
'data' => [
new FormattableMarkup('
@id
', ['@id' => $element_plugin_id]),
@@ -206,6 +222,9 @@ class WebformPluginElementController extends ControllerBase implements Container
$operations ? ['data' => ['#type' => 'operations', '#links' => $operations]] : '',
],
];
+ if (isset($excluded_types[$element_plugin_id])) {
+ $webform_form_element_rows[$element_plugin_id]['class'] = ['color-warning'];
+ }
}
else {
$element_rows[$element_plugin_id] = [
diff --git a/src/Controller/WebformPluginExporterController.php b/src/Controller/WebformPluginExporterController.php
index d105c627..8efff2e9 100644
--- a/src/Controller/WebformPluginExporterController.php
+++ b/src/Controller/WebformPluginExporterController.php
@@ -2,6 +2,7 @@
namespace Drupal\webform\Controller;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
@@ -13,6 +14,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
class WebformPluginExporterController extends ControllerBase implements ContainerInjectionInterface {
/**
+ * The config factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* A results exporter plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
@@ -22,10 +30,13 @@ class WebformPluginExporterController extends ControllerBase implements Containe
/**
* Constructs a WebformPluginExporterController object.
*
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The factory for configuration objects.
* @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
* A results exporter plugin manager.
*/
- public function __construct(PluginManagerInterface $plugin_manager) {
+ public function __construct(ConfigFactoryInterface $config_factory, PluginManagerInterface $plugin_manager) {
+ $this->configFactory = $config_factory;
$this->pluginManager = $plugin_manager;
}
@@ -34,6 +45,7 @@ class WebformPluginExporterController extends ControllerBase implements Containe
*/
public static function create(ContainerInterface $container) {
return new static(
+ $container->get('config.factory'),
$container->get('plugin.manager.webform.exporter')
);
}
@@ -42,17 +54,25 @@ class WebformPluginExporterController extends ControllerBase implements Containe
* {@inheritdoc}
*/
public function index() {
+ $excluded_exporters = $this->config('webform.settings')->get('export.excluded_exporters');
+
$definitions = $this->pluginManager->getDefinitions();
$definitions = $this->pluginManager->getSortedDefinitions($definitions);
$rows = [];
foreach ($definitions as $plugin_id => $definition) {
$rows[$plugin_id] = [
- $plugin_id,
- $definition['label'],
- $definition['description'],
- $definition['provider'],
+ 'data' => [
+ $plugin_id,
+ $definition['label'],
+ $definition['description'],
+ (isset($excluded_exporters[$plugin_id])) ? $this->t('Yes') : $this->t('No'),
+ $definition['provider'],
+ ],
];
+ if (isset($excluded_exporters[$plugin_id])) {
+ $rows[$plugin_id]['class'] = ['color-warning'];
+ }
}
ksort($rows);
@@ -62,6 +82,7 @@ class WebformPluginExporterController extends ControllerBase implements Containe
$this->t('ID'),
$this->t('Label'),
$this->t('Description'),
+ $this->t('Excluded'),
$this->t('Provided by'),
],
'#rows' => $rows,
diff --git a/src/Controller/WebformPluginHandlerController.php b/src/Controller/WebformPluginHandlerController.php
index bb1e8ddf..c4a94f38 100644
--- a/src/Controller/WebformPluginHandlerController.php
+++ b/src/Controller/WebformPluginHandlerController.php
@@ -3,6 +3,7 @@
namespace Drupal\webform\Controller;
use Drupal\Component\Plugin\PluginManagerInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\DependencyInjection\ContainerInjectionInterface;
use Drupal\Core\Url;
@@ -18,6 +19,13 @@ use Symfony\Component\HttpFoundation\Request;
class WebformPluginHandlerController extends ControllerBase implements ContainerInjectionInterface {
/**
+ * The config factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* A webform handler plugin manager.
*
* @var \Drupal\Component\Plugin\PluginManagerInterface
@@ -27,10 +35,13 @@ class WebformPluginHandlerController extends ControllerBase implements Container
/**
* Constructs a WebformPluginHanderController object.
*
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The factory for configuration objects.
* @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
* A webform handler plugin manager.
*/
- public function __construct(PluginManagerInterface $plugin_manager) {
+ public function __construct(ConfigFactoryInterface $config_factory, PluginManagerInterface $plugin_manager) {
+ $this->configFactory = $config_factory;
$this->pluginManager = $plugin_manager;
}
@@ -39,6 +50,7 @@ class WebformPluginHandlerController extends ControllerBase implements Container
*/
public static function create(ContainerInterface $container) {
return new static(
+ $container->get('config.factory'),
$container->get('plugin.manager.webform.handler')
);
}
@@ -47,21 +59,29 @@ class WebformPluginHandlerController extends ControllerBase implements Container
* {@inheritdoc}
*/
public function index() {
+ $excluded_handlers = $this->config('webform.settings')->get('handler.excluded_handlers');
+
$definitions = $this->pluginManager->getDefinitions();
$definitions = $this->pluginManager->getSortedDefinitions($definitions);
$rows = [];
foreach ($definitions as $plugin_id => $definition) {
$rows[$plugin_id] = [
- $plugin_id,
- $definition['label'],
- $definition['description'],
- $definition['category'],
- ($definition['cardinality'] == -1) ? $this->t('Unlimited') : $definition['cardinality'],
- $definition['submission'] ? $this->t('Required') : $this->t('Optional'),
- $definition['results'] ? $this->t('Processed') : $this->t('Ignored'),
- $definition['provider'],
+ 'data' => [
+ $plugin_id,
+ $definition['label'],
+ $definition['description'],
+ $definition['category'],
+ (isset($excluded_handlers[$plugin_id])) ? $this->t('Yes') : $this->t('No'),
+ ($definition['cardinality'] == -1) ? $this->t('Unlimited') : $definition['cardinality'],
+ $definition['submission'] ? $this->t('Required') : $this->t('Optional'),
+ $definition['results'] ? $this->t('Processed') : $this->t('Ignored'),
+ $definition['provider'],
+ ],
];
+ if (isset($excluded_handlers[$plugin_id])) {
+ $rows[$plugin_id]['class'] = ['color-warning'];
+ }
}
ksort($rows);
@@ -72,6 +92,7 @@ class WebformPluginHandlerController extends ControllerBase implements Container
$this->t('Label'),
$this->t('Description'),
$this->t('Category'),
+ $this->t('Excluded'),
$this->t('Cardinality'),
$this->t('Database'),
$this->t('Results'),
@@ -103,6 +124,7 @@ class WebformPluginHandlerController extends ControllerBase implements Container
$definitions = $this->pluginManager->getDefinitions();
$definitions = $this->pluginManager->getSortedDefinitions($definitions);
+ $definitions = $this->pluginManager->removeExcludeDefinitions($definitions);
$rows = [];
foreach ($definitions as $plugin_id => $definition) {
diff --git a/src/Form/WebformAdminSettingsForm.php b/src/Form/WebformAdminSettingsForm.php
index 3c600e77..22addbac 100644
--- a/src/Form/WebformAdminSettingsForm.php
+++ b/src/Form/WebformAdminSettingsForm.php
@@ -2,6 +2,7 @@
namespace Drupal\webform\Form;
+use Drupal\Component\Plugin\PluginManagerInterface;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Xss;
@@ -16,6 +17,8 @@ use Drupal\webform\Entity\Webform;
use Drupal\webform\Utility\WebformArrayHelper;
use Drupal\webform\WebformAddonsManagerInterface;
use Drupal\webform\WebformElementManagerInterface;
+use Drupal\webform\WebformExporterManagerInterface;
+use Drupal\webform\WebformHandlerManagerInterface;
use Drupal\webform\WebformLibrariesManagerInterface;
use Drupal\webform\WebformSubmissionExporterInterface;
use Drupal\webform\WebformTokenManagerInterface;
@@ -42,6 +45,20 @@ class WebformAdminSettingsForm extends ConfigFormBase {
protected $elementManager;
/**
+ * The webform handler manager.
+ *
+ * @var \Drupal\webform\WebformHandlerManagerInterface
+ */
+ protected $handlerManager;
+
+ /**
+ * The webform exporter manager.
+ *
+ * @var \Drupal\webform\WebformExporterManagerInterface
+ */
+ protected $exporterManager;
+
+ /**
* The webform submission exporter.
*
* @var \Drupal\webform\WebformSubmissionExporterInterface
@@ -81,7 +98,7 @@ class WebformAdminSettingsForm extends ConfigFormBase {
*
* @var array
*/
- protected $elementTypes;
+ protected $elementIds;
/**
* {@inheritdoc}
@@ -106,6 +123,10 @@ class WebformAdminSettingsForm extends ConfigFormBase {
* The module handler.
* @param \Drupal\webform\WebformElementManagerInterface $element_manager
* The webform element manager.
+ * @param \Drupal\webform\WebformHandlerManagerInterface $handler_manager
+ * The webform handler manager.
+ * @param \Drupal\webform\WebformExporterManagerInterface $exporter_manager
+ * The webform exporter manager.
* @param \Drupal\webform\WebformSubmissionExporterInterface $submission_exporter
* The webform submission exporter.
* @param \Drupal\webform\WebformTokenManagerInterface $token_manager
@@ -117,10 +138,12 @@ class WebformAdminSettingsForm extends ConfigFormBase {
* @param \Drupal\webform\WebformAddonsManagerInterface $addons_manager
* The add-ons manager.
*/
- public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformElementManagerInterface $element_manager, WebformSubmissionExporterInterface $submission_exporter, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager, WebformThirdPartySettingsManagerInterface $third_party_settings_manager, WebformAddonsManagerInterface $addons_manager) {
+ public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, WebformElementManagerInterface $element_manager, WebformHandlerManagerInterface $handler_manager, WebformExporterManagerInterface $exporter_manager, WebformSubmissionExporterInterface $submission_exporter, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager, WebformThirdPartySettingsManagerInterface $third_party_settings_manager, WebformAddonsManagerInterface $addons_manager) {
parent::__construct($config_factory);
$this->moduleHandler = $module_handler;
$this->elementManager = $element_manager;
+ $this->handlerManager = $handler_manager;
+ $this->exporterManager = $exporter_manager;
$this->submissionExporter = $submission_exporter;
$this->tokenManager = $token_manager;
$this->librariesManager = $libraries_manager;
@@ -136,6 +159,8 @@ class WebformAdminSettingsForm extends ConfigFormBase {
$container->get('config.factory'),
$container->get('module_handler'),
$container->get('plugin.manager.webform.element'),
+ $container->get('plugin.manager.webform.handler'),
+ $container->get('plugin.manager.webform.exporter'),
$container->get('webform_submission.exporter'),
$container->get('webform.token_manager'),
$container->get('webform.libraries_manager'),
@@ -150,7 +175,6 @@ class WebformAdminSettingsForm extends ConfigFormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('webform.settings');
$settings = $config->get('settings');
- $element_plugins = $this->elementManager->getInstances();
// Page.
$form['page'] = [
@@ -548,31 +572,15 @@ class WebformAdminSettingsForm extends ConfigFormBase {
];
// (Excluded) Types.
- $types_header = [
- 'title' => ['data' => $this->t('Title')],
- 'type' => ['data' => $this->t('Type')],
- ];
- $this->elementTypes = [];
- $types_options = [];
- foreach ($element_plugins as $element_id => $element_plugin) {
- $this->elementTypes[$element_id] = $element_id;
- $types_options[$element_id] = [
- 'title' => $element_plugin->getPluginLabel(),
- 'type' => $element_plugin->getTypeName(),
- ];
- }
$form['types'] = [
'#type' => 'details',
'#title' => $this->t('Element types'),
'#description' => $this->t('Select available element types'),
];
- $form['types']['excluded_types'] = [
- '#type' => 'tableselect',
- '#header' => $types_header,
- '#options' => $types_options,
- '#required' => TRUE,
- '#default_value' => array_diff($this->elementTypes, $config->get('elements.excluded_types')),
- ];
+ $form['types']['excluded_types'] = $this->buildExcludedPlugins(
+ $this->elementManager,
+ $config->get('elements.excluded_types')
+ );
// File.
$form['file'] = [
@@ -621,6 +629,7 @@ class WebformAdminSettingsForm extends ConfigFormBase {
'#title' => $this->t('Format default settings'),
'#tree' => TRUE,
];
+ $element_plugins = $this->elementManager->getInstances();
foreach ($element_plugins as $element_id => $element_plugin) {
// Element.
$element_plugin_definition = $element_plugin->getPluginDefinition();
@@ -666,6 +675,32 @@ class WebformAdminSettingsForm extends ConfigFormBase {
}
}
+ // (Excluded) Handlers.
+ $form['handler'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Submission handlers'),
+ '#description' => $this->t('Select available submission handlers'),
+ ];
+ $form['handler']['excluded_handlers'] = $this->buildExcludedPlugins(
+ $this->handlerManager,
+ $config->get('handler.excluded_handlers')
+ );
+ $excluded_handler_checkboxes = [];
+ foreach ($form['handler']['excluded_handlers']['#options'] as $handler_id => $option) {
+ if ($excluded_handler_checkboxes) {
+ $excluded_handler_checkboxes[] = 'or';
+ }
+ $excluded_handler_checkboxes[] = [':input[name="excluded_handlers[' . $handler_id . ']"]' => ['checked' => FALSE]];
+ }
+ $form['handler']['excluded_handlers_message'] = [
+ '#type' => 'webform_message',
+ '#message_message' => $this->t('All excluded handlers must be manually removed from existing webforms.'),
+ '#message_type' => 'warning',
+ '#states' => [
+ 'visible' => $excluded_handler_checkboxes,
+ ],
+ ];
+
// Mail.
$form['mail'] = [
'#type' => 'details',
@@ -738,6 +773,17 @@ class WebformAdminSettingsForm extends ConfigFormBase {
$export_form_state = new FormState();
$this->submissionExporter->buildExportOptionsForm($form, $export_form_state, $export_options);
+ // (Excluded) Exporters.
+ $form['exporters'] = [
+ '#type' => 'details',
+ '#title' => $this->t('Submission exporters'),
+ '#description' => $this->t('Select available submission exporters'),
+ ];
+ $form['exporters']['excluded_exporters'] = $this->buildExcludedPlugins(
+ $this->exporterManager,
+ $config->get('export.excluded_exporters') ?: [] ?: []
+ );
+
// Batch.
$form['batch'] = [
'#type' => 'details',
@@ -1030,19 +1076,21 @@ class WebformAdminSettingsForm extends ConfigFormBase {
/* Excluded types */
- // Convert list of included types to excluded types.
- $excluded_types = array_diff($this->elementTypes, array_filter($form_state->getValue('excluded_types')));
- ksort($excluded_types);
+ // Convert list of included elements, handlers, exporters to excluded.
+ $excluded_elements = $this->convertIncludedToExcludedPluginIds($this->elementManager, $form_state->getValue('excluded_types'));
+ $excluded_handlers = $this->convertIncludedToExcludedPluginIds($this->handlerManager, $form_state->getValue('excluded_handlers'));
+ $excluded_exporters = $this->convertIncludedToExcludedPluginIds($this->exporterManager, $form_state->getValue('excluded_exporters'));
/* Config save */
$config = $this->config('webform.settings');
$config->set('settings', $settings);
$config->set('assets', $form_state->getValue('assets'));
- $config->set('elements', $form_state->getValue('elements') + ['excluded_types' => $excluded_types]);
+ $config->set('elements', $form_state->getValue('elements') + ['excluded_types' => $excluded_elements]);
$config->set('file', $form_state->getValue('file'));
$config->set('format', $format);
+ $config->set('handler', ['excluded_handlers' => $excluded_handlers]);
$config->set('mail', $form_state->getValue('mail'));
- $config->set('export', $this->submissionExporter->getValuesFromInput($form_state->getValues()));
+ $config->set('export', $this->submissionExporter->getValuesFromInput($form_state->getValues()) + ['excluded_exporters' => $excluded_exporters]);
$config->set('batch', $form_state->getValue('batch'));
$config->set('purge_settings', $form_state->getValue('purge_settings'));
$config->set('test', $form_state->getValue('test'));
@@ -1088,4 +1136,76 @@ class WebformAdminSettingsForm extends ConfigFormBase {
}
}
+ /****************************************************************************/
+ // Exclude plugins
+ /****************************************************************************/
+
+ /**
+ * Build excluded plugins element.
+ *
+ * @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
+ * A webform element, handler, or exporter plugin manager.
+ * @param array $excluded_ids
+ * An array of excluded ids.
+ *
+ * @return array
+ * A table select element used to excluded plugins by id.
+ */
+ protected function buildExcludedPlugins(PluginManagerInterface $plugin_manager, array $excluded_ids) {
+ $plugins = $plugin_manager->getDefinitions();
+ $plugins = $plugin_manager->getSortedDefinitions($plugins);
+
+ $header = [
+ 'title' => ['data' => $this->t('Title')],
+ 'id' => ['data' => $this->t('Name'), 'class' => [RESPONSIVE_PRIORITY_LOW]],
+ 'description' => ['data' => $this->t('Description'), 'class' => [RESPONSIVE_PRIORITY_LOW]],
+ ];
+
+ $ids = [];
+ $options = [];
+ foreach ($plugins as $id => $plugin_definition) {
+ $ids[$id] = $id;
+ $options[$id] = [
+ 'title' => $plugin_definition['label'],
+ 'id' => $plugin_definition['id'],
+ 'description' => $plugin_definition['description'],
+ ];
+ }
+
+ return [
+ '#type' => 'tableselect',
+ '#header' => $header,
+ '#options' => $options,
+ '#required' => TRUE,
+ '#default_value' => array_diff($ids, $excluded_ids),
+ ];
+ }
+
+ /**
+ * Convert included ids returned from table select element to excluded ids.
+ *
+ * @param \Drupal\Component\Plugin\PluginManagerInterface $plugin_manager
+ * A webform element, handler, or exporter plugin manager.
+ * @param array $included_ids
+ * An array of included_ids.
+ *
+ * @return array
+ * An array of excluded ids.
+ *
+ * @see \Drupal\webform\Form\WebformAdminSettingsForm::buildExcludedPlugins
+ */
+ protected function convertIncludedToExcludedPluginIds(PluginManagerInterface $plugin_manager, array $included_ids) {
+ $plugins = $plugin_manager->getDefinitions();
+ $plugins = $plugin_manager->getSortedDefinitions($plugins);
+
+ $ids = [];
+ foreach ($plugins as $id => $plugin) {
+ $ids[$id] = $id;
+ }
+
+ $excluded_ids = array_diff($ids, array_filter($included_ids));
+ ksort($excluded_ids);
+ return $excluded_ids;
+ }
+
}
diff --git a/src/Form/WebformHandlerAddForm.php b/src/Form/WebformHandlerAddForm.php
index 97a0db9e..71be3755 100644
--- a/src/Form/WebformHandlerAddForm.php
+++ b/src/Form/WebformHandlerAddForm.php
@@ -6,6 +6,7 @@ use Drupal\Core\Form\FormStateInterface;
use Drupal\webform\WebformHandlerManagerInterface;
use Drupal\webform\WebformInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
+use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
/**
* Provides an add form for webform handler.
@@ -43,6 +44,11 @@ class WebformHandlerAddForm extends WebformHandlerFormBase {
*/
public function buildForm(array $form, FormStateInterface $form_state, WebformInterface $webform = NULL, $webform_handler = NULL) {
$form = parent::buildForm($form, $form_state, $webform, $webform_handler);
+ // Throw access denied is handler is excluded.
+ if ($this->webformHandler->isExcluded()) {
+ throw new AccessDeniedHttpException();
+ }
+
$form['#title'] = $this->t('Add @label handler', ['@label' => $this->webformHandler->label()]);
return $form;
}
diff --git a/src/Plugin/WebformHandler/EmailWebformHandler.php b/src/Plugin/WebformHandler/EmailWebformHandler.php
index c60f7f3a..1be4655d 100644
--- a/src/Plugin/WebformHandler/EmailWebformHandler.php
+++ b/src/Plugin/WebformHandler/EmailWebformHandler.php
@@ -101,10 +101,9 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
/**
* {@inheritdoc}
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, ConfigFactoryInterface $config_factory, MailManagerInterface $mail_manager, WebformTokenManagerInterface $token_manager, WebformElementManagerInterface $element_manager) {
- parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $entity_type_manager);
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, AccountInterface $current_user, MailManagerInterface $mail_manager, WebformTokenManagerInterface $token_manager, WebformElementManagerInterface $element_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $config_factory, $entity_type_manager);
$this->currentUser = $current_user;
- $this->configFactory = $config_factory;
$this->mailManager = $mail_manager;
$this->tokenManager = $token_manager;
$this->elementManager = $element_manager;
@@ -119,9 +118,9 @@ class EmailWebformHandler extends WebformHandlerBase implements WebformHandlerMe
$plugin_id,
$plugin_definition,
$container->get('logger.factory')->get('webform.email'),
+ $container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('current_user'),
- $container->get('config.factory'),
$container->get('plugin.manager.mail'),
$container->get('webform.token_manager'),
$container->get('plugin.manager.webform.element')
diff --git a/src/Plugin/WebformHandler/RemotePostWebformHandler.php b/src/Plugin/WebformHandler/RemotePostWebformHandler.php
index db31482d..41d1bc69 100644
--- a/src/Plugin/WebformHandler/RemotePostWebformHandler.php
+++ b/src/Plugin/WebformHandler/RemotePostWebformHandler.php
@@ -2,6 +2,7 @@
namespace Drupal\webform\Plugin\WebformHandler;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Serialization\Yaml;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -54,8 +55,8 @@ class RemotePostWebformHandler extends WebformHandlerBase {
/**
* {@inheritdoc}
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, ClientInterface $http_client, WebformTokenManagerInterface $token_manager) {
- parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $entity_type_manager);
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, ModuleHandlerInterface $module_handler, ClientInterface $http_client, WebformTokenManagerInterface $token_manager) {
+ parent::__construct($configuration, $plugin_id, $plugin_definition, $logger, $config_factory, $entity_type_manager);
$this->moduleHandler = $module_handler;
$this->httpClient = $http_client;
$this->tokenManager = $token_manager;
@@ -70,6 +71,7 @@ class RemotePostWebformHandler extends WebformHandlerBase {
$plugin_id,
$plugin_definition,
$container->get('logger.factory')->get('webform.remote_post'),
+ $container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('module_handler'),
$container->get('http_client'),
diff --git a/src/WebformElementBase.php b/src/WebformElementBase.php
index 08b0f6f5..6dd6c734 100644
--- a/src/WebformElementBase.php
+++ b/src/WebformElementBase.php
@@ -124,10 +124,8 @@ class WebformElementBase extends PluginBase implements WebformElementInterface {
* The token manager.
* @param \Drupal\webform\WebformLibrariesManagerInterface $libraries_manager
* The libraries manager.
- * @param \Drupal\webform\WebformSubmissionStorageInterface $webform_submission_storage
- * The webform submission storage.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager, WebformSubmissionStorageInterface $webform_submission_storage) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager, ElementInfoManagerInterface $element_info, WebformElementManagerInterface $element_manager, WebformTokenManagerInterface $token_manager, WebformLibrariesManagerInterface $libraries_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->logger = $logger;
$this->configFactory = $config_factory;
@@ -137,7 +135,7 @@ class WebformElementBase extends PluginBase implements WebformElementInterface {
$this->elementManager = $element_manager;
$this->tokenManager = $token_manager;
$this->librariesManager = $libraries_manager;
- $this->submissionStorage = $webform_submission_storage;
+ $this->submissionStorage = $entity_type_manager->getStorage('webform_submission');
}
/**
@@ -155,8 +153,7 @@ class WebformElementBase extends PluginBase implements WebformElementInterface {
$container->get('plugin.manager.element_info'),
$container->get('plugin.manager.webform.element'),
$container->get('webform.token_manager'),
- $container->get('webform.libraries_manager'),
- $container->get('entity_type.manager')->getStorage('webform_submission')
+ $container->get('webform.libraries_manager')
);
}
@@ -394,8 +391,15 @@ class WebformElementBase extends PluginBase implements WebformElementInterface {
/**
* {@inheritdoc}
*/
+ public function isExcluded() {
+ return $this->configFactory->get('webform.settings')->get('elements.excluded_types.' . $this->pluginDefinition['id']) ? TRUE : FALSE;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function isEnabled() {
- return \Drupal::config('webform.settings')->get('elements.excluded_types.' . $this->pluginDefinition['id']) ? FALSE : TRUE;
+ return !$this->isExcluded();
}
/**
@@ -1608,8 +1612,7 @@ class WebformElementBase extends PluginBase implements WebformElementInterface {
'#type' => 'textfield',
'#title' => $this->t('Placeholder'),
'#description' => $this->t('The placeholder will be shown in the element until the user starts entering a value.'),
- '#maxlength' => 255,
- ];
+ 7 ];
$form['form']['autocomplete'] = [
'#type' => 'select',
'#title' => $this->t('Autocomplete'),
diff --git a/src/WebformElementInterface.php b/src/WebformElementInterface.php
index 1299b04d..71078eb5 100644
--- a/src/WebformElementInterface.php
+++ b/src/WebformElementInterface.php
@@ -175,6 +175,14 @@ interface WebformElementInterface extends PluginInspectionInterface, PluginFormI
public function isHidden();
/**
+ * Checks if the element is excluded via webform.settings.
+ *
+ * @return bool
+ * TRUE if the element is excluded.
+ */
+ public function isExcluded();
+
+ /**
* Checks if the element is enabled.
*
* @return bool
diff --git a/src/WebformElementManager.php b/src/WebformElementManager.php
index 094ec895..350a1702 100644
--- a/src/WebformElementManager.php
+++ b/src/WebformElementManager.php
@@ -4,6 +4,7 @@ namespace Drupal\webform;
use Drupal\Component\Plugin\FallbackPluginManagerInterface;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
@@ -23,6 +24,13 @@ class WebformElementManager extends DefaultPluginManager implements FallbackPlug
use CategorizingPluginManagerTrait;
/**
+ * The configuration object factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* A element info manager.
*
* @var \Drupal\Core\Render\ElementInfoManagerInterface
@@ -46,11 +54,14 @@ class WebformElementManager extends DefaultPluginManager implements FallbackPlug
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration object factory.
* @param \Drupal\Core\Render\ElementInfoManagerInterface $element_info
* The element info manager.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ElementInfoManagerInterface $element_info) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory, ElementInfoManagerInterface $element_info) {
parent::__construct('Plugin/WebformElement', $namespaces, $module_handler, 'Drupal\webform\WebformElementInterface', 'Drupal\webform\Annotation\WebformElement');
+ $this->configFactory = $config_factory;
$this->elementInfo = $element_info;
$this->alterInfo('webform_element_info');
@@ -112,12 +123,7 @@ class WebformElementManager extends DefaultPluginManager implements FallbackPlug
public function getInstances() {
$plugin_definitions = $this->getDefinitions();
$plugin_definitions = $this->getSortedDefinitions($plugin_definitions);
-
- // If all the plugin definitions are initialize returned the cached
- // instances.
- if (count($plugin_definitions) == count($this->instances)) {
- return $this->instances;
- }
+ $plugin_definitions = $this->removeExcludeDefinitions($plugin_definitions);
// Initialize and return all plugin instances.
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
@@ -218,6 +224,20 @@ class WebformElementManager extends DefaultPluginManager implements FallbackPlug
/**
* {@inheritdoc}
*/
+ public function removeExcludeDefinitions(array $definitions) {
+ $definitions = isset($definitions) ? $definitions : $this->getDefinitions();
+ $excluded = $this->configFactory->get('webform.settings')->get('element.excluded_types');
+ foreach ($definitions as $id => $definition) {
+ if (isset($excluded[$id])) {
+ unset($definitions[$id]);
+ }
+ }
+ return $definitions;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getTranslatableProperties() {
$properties = [];
$webform_elements = $this->getInstances();
diff --git a/src/WebformElementManagerInterface.php b/src/WebformElementManagerInterface.php
index 89dce785..5d7ed8d7 100644
--- a/src/WebformElementManagerInterface.php
+++ b/src/WebformElementManagerInterface.php
@@ -79,6 +79,16 @@ interface WebformElementManagerInterface extends PluginManagerInterface, CachedD
public function getSortedDefinitions(array $definitions = NULL, $sort_by = 'label');
/**
+ * Remove excluded plugin definitions.
+ *
+ * @param array $definitions
+ * The plugin definitions to filter
+ * @return array
+ * An array of plugin definitions with excluded plugins removed.
+ */
+ public function removeExcludeDefinitions(array $definitions);
+
+ /**
* Get all translatable properties from all elements.
*
* @return array
diff --git a/src/WebformEntityHandlersForm.php b/src/WebformEntityHandlersForm.php
index 40e1fa2c..abb2c551 100644
--- a/src/WebformEntityHandlersForm.php
+++ b/src/WebformEntityHandlersForm.php
@@ -117,20 +117,32 @@ class WebformEntityHandlersForm extends EntityForm {
800,
['button', 'button-action', 'button--primary', 'button--small']
);
- $form['local_actions'] = [
- 'add_element' => [
+
+ // Filter add handler by excluded_handlers.
+ /** @var \Drupal\webform\WebformHandlerManagerInterface $handler_manager */
+ $handler_manager = \Drupal::service('plugin.manager.webform.handler');
+ $handler_definitions = $handler_manager->getDefinitions();
+ $handler_definitions = $handler_manager->removeExcludeDefinitions($handler_definitions);
+ unset($handler_definitions['broken']);
+
+ $form['local_actions'] = [];
+ if (isset($handler_definitions['email'])) {
+ $form['local_actions']['add_email'] = [
'#type' => 'link',
'#title' => $this->t('Add email'),
'#url' => new Url('entity.webform.handler.add_form', ['webform' => $webform->id(), 'webform_handler' => 'email']),
'#attributes' => $dialog_attributes,
- 'add_page' => [
- '#type' => 'link',
- '#title' => $this->t('Add handler'),
- '#url' => new Url('entity.webform.handlers', ['webform' => $webform->id()]),
- '#attributes' => $dialog_attributes,
- ],
- ],
- ];
+ ];
+ }
+ unset($handler_definitions['email']);
+ if ($handler_definitions) {
+ $form['local_actions']['add_handler'] = [
+ '#type' => 'link',
+ '#title' => $this->t('Add handler'),
+ '#url' => new Url('entity.webform.handlers', ['webform' => $webform->id()]),
+ '#attributes' => $dialog_attributes,
+ ];
+ }
// Build the list of existing webform handlers for this webform.
$form['handlers'] = [
diff --git a/src/WebformExporterBase.php b/src/WebformExporterBase.php
index 2dc48b5a..e2214730 100644
--- a/src/WebformExporterBase.php
+++ b/src/WebformExporterBase.php
@@ -2,6 +2,7 @@
namespace Drupal\webform;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
@@ -26,6 +27,13 @@ abstract class WebformExporterBase extends PluginBase implements WebformExporter
protected $logger;
/**
+ * The configuration factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
@@ -57,16 +65,19 @@ abstract class WebformExporterBase extends PluginBase implements WebformExporter
* The plugin implementation definition.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration factory.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\webform\WebformElementManagerInterface $element_manager
* The webform element manager.
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager, WebformElementManagerInterface $element_manager) {
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager, WebformElementManagerInterface $element_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
$this->logger = $logger;
+ $this->configFactory = $config_factory;
$this->entityTypeManager = $entity_type_manager;
$this->entityStorage = $entity_type_manager->getStorage('webform_submission');
$this->elementManager = $element_manager;
@@ -81,6 +92,7 @@ abstract class WebformExporterBase extends PluginBase implements WebformExporter
$plugin_id,
$plugin_definition,
$container->get('logger.factory')->get('webform'),
+ $container->get('config.factory'),
$container->get('entity_type.manager'),
$container->get('plugin.manager.webform.element')
);
@@ -110,6 +122,13 @@ abstract class WebformExporterBase extends PluginBase implements WebformExporter
/**
* {@inheritdoc}
*/
+ public function isExcluded() {
+ return $this->configFactory->get('webform.settings')->get('export.excluded_exporters.' . $this->pluginDefinition['id']) ? TRUE : FALSE;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function isArchive() {
return $this->pluginDefinition['archive'];
}
diff --git a/src/WebformExporterInterface.php b/src/WebformExporterInterface.php
index b4c939e1..41fc393d 100644
--- a/src/WebformExporterInterface.php
+++ b/src/WebformExporterInterface.php
@@ -35,6 +35,14 @@ interface WebformExporterInterface extends PluginInspectionInterface, Configurab
public function description();
/**
+ * Checks if the exporter is excluded via webform.settings.
+ *
+ * @return bool
+ * TRUE if the exporter is excluded.
+ */
+ public function isExcluded();
+
+ /**
* Determine if exporter generates an archive.
*
* @return bool
diff --git a/src/WebformExporterManager.php b/src/WebformExporterManager.php
index 634970d1..6d8139a5 100644
--- a/src/WebformExporterManager.php
+++ b/src/WebformExporterManager.php
@@ -3,6 +3,7 @@
namespace Drupal\webform;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
@@ -23,6 +24,13 @@ class WebformExporterManager extends DefaultPluginManager implements WebformExpo
}
/**
+ * The configuration object factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* Constructs a WebformExporterManager.
*
* @param \Traversable $namespaces
@@ -32,9 +40,12 @@ class WebformExporterManager extends DefaultPluginManager implements WebformExpo
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_exporter
* The module exporter.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration object factory.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_exporter) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_exporter, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/WebformExporter', $namespaces, $module_exporter, 'Drupal\webform\WebformExporterInterface', 'Drupal\webform\Annotation\WebformExporter');
+ $this->configFactory = $config_factory;
$this->alterInfo('webform_exporter_info');
$this->setCacheBackend($cache_backend, 'webform_exporter_plugins');
@@ -52,10 +63,25 @@ class WebformExporterManager extends DefaultPluginManager implements WebformExpo
/**
* {@inheritdoc}
*/
+ public function removeExcludeDefinitions(array $definitions) {
+ $definitions = isset($definitions) ? $definitions : $this->getDefinitions();
+ $excluded = $this->configFactory->get('webform.settings')->get('export.excluded_exporters');
+ foreach ($definitions as $id => $definition) {
+ if (isset($excluded[$id])) {
+ unset($definitions[$id]);
+ }
+ }
+ return $definitions;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getInstances(array $configuration = []) {
$instances = [];
$plugin_definitions = $this->getDefinitions();
$plugin_definitions = $this->getSortedDefinitions($plugin_definitions);
+ $plugin_definitions = $this->removeExcludeDefinitions($plugin_definitions);
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
$instances[$plugin_id] = $this->createInstance($plugin_id, $configuration);
}
@@ -68,6 +94,7 @@ class WebformExporterManager extends DefaultPluginManager implements WebformExpo
public function getOptions() {
$plugin_definitions = $this->getDefinitions();
$plugin_definitions = $this->getSortedDefinitions($plugin_definitions);
+ $plugin_definitions = $this->removeExcludeDefinitions($plugin_definitions);
$options = [];
foreach ($plugin_definitions as $plugin_id => $plugin_definition) {
diff --git a/src/WebformExporterManagerInterface.php b/src/WebformExporterManagerInterface.php
index ef1d0818..cb310574 100644
--- a/src/WebformExporterManagerInterface.php
+++ b/src/WebformExporterManagerInterface.php
@@ -13,6 +13,16 @@ use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
interface WebformExporterManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface, FallbackPluginManagerInterface, CategorizingPluginManagerInterface {
/**
+ * Remove excluded plugin definitions.
+ *
+ * @param array $definitions
+ * The plugin definitions to filter
+ * @return array
+ * An array of plugin definitions with excluded plugins removed.
+ */
+ public function removeExcludeDefinitions(array $definitions);
+
+ /**
* Get all available webform element plugin instances.
*
* @param array $configuration
diff --git a/src/WebformHandlerBase.php b/src/WebformHandlerBase.php
index 210f2200..04b5b2bc 100644
--- a/src/WebformHandlerBase.php
+++ b/src/WebformHandlerBase.php
@@ -2,6 +2,7 @@
namespace Drupal\webform;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\PluginBase;
@@ -61,6 +62,13 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn
protected $logger;
/**
+ * The configuration factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* Webform submission storage.
*
* @var \Drupal\webform\WebformSubmissionStorageInterface
@@ -70,11 +78,28 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn
/**
* {@inheritdoc}
*/
- public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, EntityTypeManagerInterface $entity_type_manager) {
+ /**
+ * Constructs a WebformElementBast object.
+ *
+ * @param array $configuration
+ * A configuration array containing information about the plugin instance.
+ * @param string $plugin_id
+ * The plugin_id for the plugin instance.
+ * @param mixed $plugin_definition
+ * The plugin implementation definition.
+ * @param \Psr\Log\LoggerInterface $logger
+ * A logger instance.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration factory.
+ * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
+ * The entity type manager.
+ */
+ public function __construct(array $configuration, $plugin_id, $plugin_definition, LoggerInterface $logger, ConfigFactoryInterface $config_factory, EntityTypeManagerInterface $entity_type_manager) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->setConfiguration($configuration);
$this->logger = $logger;
+ $this->configFactory = $config_factory;
$this->submissionStorage = $entity_type_manager->getStorage('webform_submission');
}
@@ -87,6 +112,7 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn
$plugin_id,
$plugin_definition,
$container->get('logger.factory')->get('webform'),
+ $container->get('config.factory'),
$container->get('entity_type.manager')
);
}
@@ -206,6 +232,13 @@ abstract class WebformHandlerBase extends PluginBase implements WebformHandlerIn
/**
* {@inheritdoc}
*/
+ public function isExcluded() {
+ return $this->configFactory->get('webform.settings')->get('handler.excluded_handlers.' . $this->pluginDefinition['id']) ? TRUE : FALSE;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function isEnabled() {
return $this->status ? TRUE : FALSE;
}
diff --git a/src/WebformHandlerInterface.php b/src/WebformHandlerInterface.php
index 4ca0440e..2d6444b3 100644
--- a/src/WebformHandlerInterface.php
+++ b/src/WebformHandlerInterface.php
@@ -154,6 +154,14 @@ interface WebformHandlerInterface extends PluginInspectionInterface, Configurabl
public function setStatus($status);
/**
+ * Checks if the handler is excluded via webform.settings.
+ *
+ * @return bool
+ * TRUE if the handler is excluded.
+ */
+ public function isExcluded();
+
+ /**
* Returns the webform handler enabled indicator.
*
* @return bool
diff --git a/src/WebformHandlerManager.php b/src/WebformHandlerManager.php
index e0dda148..c1ae0bdb 100644
--- a/src/WebformHandlerManager.php
+++ b/src/WebformHandlerManager.php
@@ -3,6 +3,7 @@
namespace Drupal\webform;
use Drupal\Core\Cache\CacheBackendInterface;
+use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Extension\ModuleHandlerInterface;
use Drupal\Core\Plugin\CategorizingPluginManagerTrait;
use Drupal\Core\Plugin\DefaultPluginManager;
@@ -24,6 +25,13 @@ class WebformHandlerManager extends DefaultPluginManager implements WebformHandl
}
/**
+ * The configuration object factory.
+ *
+ * @var \Drupal\Core\Config\ConfigFactoryInterface
+ */
+ protected $configFactory;
+
+ /**
* Constructs a WebformHandlerManager.
*
* @param \Traversable $namespaces
@@ -33,9 +41,12 @@ class WebformHandlerManager extends DefaultPluginManager implements WebformHandl
* Cache backend instance to use.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The module handler.
+ * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+ * The configuration object factory.
*/
- public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler) {
+ public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, ModuleHandlerInterface $module_handler, ConfigFactoryInterface $config_factory) {
parent::__construct('Plugin/WebformHandler', $namespaces, $module_handler, 'Drupal\webform\WebformHandlerInterface', 'Drupal\webform\Annotation\WebformHandler');
+ $this->configFactory = $config_factory;
$this->alterInfo('webform_handler_info');
$this->setCacheBackend($cache_backend, 'webform_handler_plugins');
@@ -65,6 +76,20 @@ class WebformHandlerManager extends DefaultPluginManager implements WebformHandl
/**
* {@inheritdoc}
*/
+ public function removeExcludeDefinitions(array $definitions) {
+ $definitions = isset($definitions) ? $definitions : $this->getDefinitions();
+ $excluded = $this->configFactory->get('webform.settings')->get('handler.excluded_handlers');
+ foreach ($definitions as $id => $definition) {
+ if (isset($excluded[$id])) {
+ unset($definitions[$id]);
+ }
+ }
+ return $definitions;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
public function getFallbackPluginId($plugin_id, array $configuration = []) {
return 'broken';
}
diff --git a/src/WebformHandlerManagerInterface.php b/src/WebformHandlerManagerInterface.php
index 186f88a1..d53b5f8e 100644
--- a/src/WebformHandlerManagerInterface.php
+++ b/src/WebformHandlerManagerInterface.php
@@ -12,4 +12,14 @@ use Drupal\Component\Plugin\CategorizingPluginManagerInterface;
*/
interface WebformHandlerManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface, FallbackPluginManagerInterface, CategorizingPluginManagerInterface {
+ /**
+ * Remove excluded plugin definitions.
+ *
+ * @param array $definitions
+ * The plugin definitions to filter
+ * @return array
+ * An array of plugin definitions with excluded plugins removed.
+ */
+ public function removeExcludeDefinitions(array $definitions);
+
}
diff --git a/webform.install b/webform.install
index 29d6e2fd..4b23cbe6 100644
--- a/webform.install
+++ b/webform.install
@@ -649,3 +649,10 @@ function _webform_update_8046_convert_data(array $data) {
return $data;
}
+
+/**
+ * Issue #2879217: Allow WebformHandlers and WebformExporters to be excluded.
+ */
+function webform_update_8047() {
+ _webform_update_admin_settings();
+}
diff --git a/webform.services.yml b/webform.services.yml
index 3c78e329..3300cb22 100644
--- a/webform.services.yml
+++ b/webform.services.yml
@@ -4,15 +4,15 @@ services:
plugin.manager.webform.element:
class: Drupal\webform\WebformElementManager
- arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@plugin.manager.element_info']
+ arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@config.factory', '@plugin.manager.element_info']
plugin.manager.webform.handler:
class: Drupal\webform\WebformHandlerManager
- parent: default_plugin_manager
+ arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@config.factory']
plugin.manager.webform.exporter:
class: Drupal\webform\WebformExporterManager
- parent: default_plugin_manager
+ arguments: ['@container.namespaces', '@cache.discovery', '@module_handler', '@config.factory']
# Logger.