Add a way to configure allowed entity types for workspace-specific config

Created on 1 July 2022, about 3 years ago
Updated 17 October 2022, almost 3 years ago

Problem/Motivation

Workspace config (wse_config) enables us to change config entities inside a workspace and to deploy them. However in order to actually enable this for any entity type, we still need to write code inside hook_entity_type_alter() to mark config entity types as internal and thus make CRUD operations for a type work inside a workspace.

If we don't do so, core's EntityOperations::shouldSkipPreOperations prevents us from using any config entity type that isn't marked as "internal".

Steps to reproduce

On Vanilla Drupal 9

  1. Enable wse_config
  2. Switch to the stage workspace
  3. Navigate to /admin/structure/block and try adding a block
  4. Workspaces will block this with an exception "This entity can only be saved in the default workspace."

Proposed resolution

Expose the relevant (some need to be excluded) config entity types on the settings form in a multi select. Then implement hook_entity_type_alter() to mark the types selected on the settings form as internal.

📌 Task
Status

Fixed

Version

1.0

Component

Workspace Config

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • There is still a problem with the linkcheckerlink config entity type which is used by the Link Checker module. When a workspace is active, and a node with a link in an HTML text field is being saved, the following error occurs:

    Drupal\Core\Entity\EntityStorageException: The "linkcheckerlink" entity type can only be saved in the default workspace. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    The linkcheckerlink config entity type needs to be added to the list of option is the Enabled config entity types multi-select field in the Workspace Settings page. I was able to get around this error by marking linkcheckerlink config entity type as "internal" inside hook_entity_type_build():

    function my_module_entity_type_build(array &$entity_types) {
      $entity_type_id = 'linkcheckerlink';
     
      if (isset($entity_types[$entity_type_id]) && $entity_types[$entity_type_id] instanceof EntityTypeInterface) {
        /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
        $entity_type = $entity_types[$entity_type_id];
     
        // Mark the entity type as internal.
        $entity_type->set('internal', TRUE);
      }
    }
Production build 0.71.5 2024