Loading modules/wse_config/config/install/wse_config.settings.yml 0 → 100644 +4 −0 Original line number Diff line number Diff line enabled_config_entity_types: - block - menu - view modules/wse_config/config/schema/wse_config.schema.yml 0 → 100644 +10 −0 Original line number Diff line number Diff line # Schema for the configuration files of the workspace config module. wse_config.settings: type: config_object label: 'Workspace config settings' mapping: enabled_config_entity_types: type: sequence label: 'Enabled entity types for workspace-specific config.' sequence: type: string modules/wse_config/src/EventSubscriber/WseConfigSubscriber.php +2 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,8 @@ class WseConfigSubscriber implements EventSubscriberInterface { 'media.*', 'pathauto.*', 'menu_item_extras.utility', 'wse_config.*', 'wse.*', ]; $event->setIgnored(...$config_names); } Loading modules/wse_config/src/WseConfigMatcher.php +51 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\wse_config; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\wse_config\Event\WseConfigEvents; use Drupal\wse_config\Event\WseConfigOptOutEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; Loading @@ -25,14 +27,24 @@ class WseConfigMatcher { */ protected $eventDispatcher; /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a WseConfigMatcher object. * * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */ public function __construct(EventDispatcherInterface $event_dispatcher) { public function __construct(EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager) { $this->eventDispatcher = $event_dispatcher; $this->entityTypeManager = $entity_type_manager; } /** Loading Loading @@ -90,6 +102,44 @@ class WseConfigMatcher { return $ignored; } /** * Gets a list of config entity types. * * Certain types get excluded as it doesn't make sense to edit those inside * a workspace for now. * * @return array * The list of allowed entity types indexed by ID. */ public function getAllowedConfigEntityTypes() { $allowed_entity_types = []; $entity_types = $this->entityTypeManager->getDefinitions(); // @todo Can we determine this dynamically? The same goes for // WseConfigSubscriber::onWseConfigOptOut() to stay consistent. $excluded = [ 'block_content_type', 'field_config', 'field_storage_config', 'node_type', 'block_content_type', 'user_role', 'entity_form_display', 'entity_view_display', 'comment_type', 'media_type', 'pathauto_pattern', 'base_field_override', 'taxonomy_vocabulary', ]; foreach ($entity_types as $type) { if ($type instanceof ConfigEntityTypeInterface && !in_array($type->id(), $excluded)) { $allowed_entity_types[$type->id()] = (string) $type->getLabel(); } } return $allowed_entity_types; } /** * Suffixes config prefixes with a wildcard character. * Loading modules/wse_config/wse_config.module +47 −9 Original line number Diff line number Diff line Loading @@ -5,19 +5,57 @@ * Provides a revisionable content storage for config entities. */ use Drupal\Core\Form\FormStateInterface; /** * Implements hook_entity_type_alter(). * * @todo how do we implement this more generically? One possibility is to just * mark all config entity types as internal? */ function wse_config_entity_type_alter(array &$entity_types) { if (!empty($entity_types['asset_injector_css'])) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['asset_injector_css']->set('internal', TRUE); $enabled_entity_types = \Drupal::config('wse_config.settings') ->get('enabled_config_entity_types'); if (!$enabled_entity_types) { return; } if (!empty($entity_types['view'])) { foreach ($enabled_entity_types as $entity_type) { if (!empty($entity_types[$entity_type])) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['view']->set('internal', TRUE); $entity_types[$entity_type]->set('internal', TRUE); } } } /** * Implements hook_form_FORM_ID_alter(). */ function wse_config_form_wse_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { $config = \Drupal::config('wse_config.settings'); $form['types_wrapper'] = [ '#type' => 'details', '#title' => t('Enabled entity types'), '#open' => TRUE, ]; $available_entity_types = \Drupal::service('wse_config.config_matcher') ->getAllowedConfigEntityTypes(); ksort($available_entity_types, SORT_STRING); $form['types_wrapper']['enabled_config_entity_types'] = [ '#type' => 'select', '#multiple' => TRUE, '#size' => 10, '#title' => t('Enabled config entity types'), '#default_value' => $config->get('enabled_config_entity_types'), '#options' => $available_entity_types, '#description' => t('Enabled config entity types can be created/edited/deleted inside workspaces'), ]; $form['#submit'][] = 'wse_config_settings_form_submit'; } /** * Additional submit handler for altered wse settings form. */ function wse_config_settings_form_submit(array &$form, FormStateInterface $form_state) { $config = \Drupal::configFactory()->getEditable('wse_config.settings'); $config->set('enabled_config_entity_types', array_values($form_state->getValue('enabled_config_entity_types'))) ->save(); } Loading
modules/wse_config/config/install/wse_config.settings.yml 0 → 100644 +4 −0 Original line number Diff line number Diff line enabled_config_entity_types: - block - menu - view
modules/wse_config/config/schema/wse_config.schema.yml 0 → 100644 +10 −0 Original line number Diff line number Diff line # Schema for the configuration files of the workspace config module. wse_config.settings: type: config_object label: 'Workspace config settings' mapping: enabled_config_entity_types: type: sequence label: 'Enabled entity types for workspace-specific config.' sequence: type: string
modules/wse_config/src/EventSubscriber/WseConfigSubscriber.php +2 −0 Original line number Diff line number Diff line Loading @@ -159,6 +159,8 @@ class WseConfigSubscriber implements EventSubscriberInterface { 'media.*', 'pathauto.*', 'menu_item_extras.utility', 'wse_config.*', 'wse.*', ]; $event->setIgnored(...$config_names); } Loading
modules/wse_config/src/WseConfigMatcher.php +51 −1 Original line number Diff line number Diff line Loading @@ -2,6 +2,8 @@ namespace Drupal\wse_config; use Drupal\Core\Config\Entity\ConfigEntityTypeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\wse_config\Event\WseConfigEvents; use Drupal\wse_config\Event\WseConfigOptOutEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; Loading @@ -25,14 +27,24 @@ class WseConfigMatcher { */ protected $eventDispatcher; /** * The entity type manager. * * @var \Drupal\Core\Entity\EntityTypeManagerInterface */ protected $entityTypeManager; /** * Constructs a WseConfigMatcher object. * * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher * The event dispatcher. * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager * The entity type manager. */ public function __construct(EventDispatcherInterface $event_dispatcher) { public function __construct(EventDispatcherInterface $event_dispatcher, EntityTypeManagerInterface $entity_type_manager) { $this->eventDispatcher = $event_dispatcher; $this->entityTypeManager = $entity_type_manager; } /** Loading Loading @@ -90,6 +102,44 @@ class WseConfigMatcher { return $ignored; } /** * Gets a list of config entity types. * * Certain types get excluded as it doesn't make sense to edit those inside * a workspace for now. * * @return array * The list of allowed entity types indexed by ID. */ public function getAllowedConfigEntityTypes() { $allowed_entity_types = []; $entity_types = $this->entityTypeManager->getDefinitions(); // @todo Can we determine this dynamically? The same goes for // WseConfigSubscriber::onWseConfigOptOut() to stay consistent. $excluded = [ 'block_content_type', 'field_config', 'field_storage_config', 'node_type', 'block_content_type', 'user_role', 'entity_form_display', 'entity_view_display', 'comment_type', 'media_type', 'pathauto_pattern', 'base_field_override', 'taxonomy_vocabulary', ]; foreach ($entity_types as $type) { if ($type instanceof ConfigEntityTypeInterface && !in_array($type->id(), $excluded)) { $allowed_entity_types[$type->id()] = (string) $type->getLabel(); } } return $allowed_entity_types; } /** * Suffixes config prefixes with a wildcard character. * Loading
modules/wse_config/wse_config.module +47 −9 Original line number Diff line number Diff line Loading @@ -5,19 +5,57 @@ * Provides a revisionable content storage for config entities. */ use Drupal\Core\Form\FormStateInterface; /** * Implements hook_entity_type_alter(). * * @todo how do we implement this more generically? One possibility is to just * mark all config entity types as internal? */ function wse_config_entity_type_alter(array &$entity_types) { if (!empty($entity_types['asset_injector_css'])) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['asset_injector_css']->set('internal', TRUE); $enabled_entity_types = \Drupal::config('wse_config.settings') ->get('enabled_config_entity_types'); if (!$enabled_entity_types) { return; } if (!empty($entity_types['view'])) { foreach ($enabled_entity_types as $entity_type) { if (!empty($entity_types[$entity_type])) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['view']->set('internal', TRUE); $entity_types[$entity_type]->set('internal', TRUE); } } } /** * Implements hook_form_FORM_ID_alter(). */ function wse_config_form_wse_settings_form_alter(&$form, FormStateInterface $form_state, $form_id) { $config = \Drupal::config('wse_config.settings'); $form['types_wrapper'] = [ '#type' => 'details', '#title' => t('Enabled entity types'), '#open' => TRUE, ]; $available_entity_types = \Drupal::service('wse_config.config_matcher') ->getAllowedConfigEntityTypes(); ksort($available_entity_types, SORT_STRING); $form['types_wrapper']['enabled_config_entity_types'] = [ '#type' => 'select', '#multiple' => TRUE, '#size' => 10, '#title' => t('Enabled config entity types'), '#default_value' => $config->get('enabled_config_entity_types'), '#options' => $available_entity_types, '#description' => t('Enabled config entity types can be created/edited/deleted inside workspaces'), ]; $form['#submit'][] = 'wse_config_settings_form_submit'; } /** * Additional submit handler for altered wse settings form. */ function wse_config_settings_form_submit(array &$form, FormStateInterface $form_state) { $config = \Drupal::configFactory()->getEditable('wse_config.settings'); $config->set('enabled_config_entity_types', array_values($form_state->getValue('enabled_config_entity_types'))) ->save(); }