Allow CRUD operations for Paragraph entities in a workspace

Created on 18 March 2024, over 1 year ago

Problem/Motivation

Paragraph entities are being referenced by their revision ID, and the Workspaces module doesn't alter those references, so it's safe to allow them to be changed in a workspace.

Proposed resolution

Allow CRUD operations for paragraph entities in a workspace by using the Drupal\workspaces\Entity\Handler\IgnoredWorkspaceHandler entity handler.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

πŸ“Œ Task
Status

Active

Version

1.0

Component

Code

Created by

πŸ‡·πŸ‡΄Romania amateescu

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

Comments & Activities

  • Issue created by @amateescu
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.4 + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    182 pass
  • πŸ‡·πŸ‡΄Romania amateescu

    This should do it.

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    Interested in this...

    I was testing this patch out and it didn't seem to change anything for me. I thought it was maybe because the Paragraph entity type has a php attribute (or whatever) now in addition to the annotation that the patch modified. More likely it's that I have wse installed and that module alters entity type info for several common entity types:

    /**
     * Implements hook_entity_type_build().
     */
    function wse_entity_type_build(array &$entity_types) {
      // Allow CRUD operations for various entity types in workspaces.
      $ignored_entity_types = [
        'crop',
        'events_logging',
        'file',
        'paragraph',
        'variant',
      ];
      foreach ($ignored_entity_types as $entity_type_id) {
        if (isset($entity_types[$entity_type_id])) {
          $entity_types[$entity_type_id]->setHandlerClass('workspace', IgnoredWorkspaceHandler::class);
        }
      }
    }

    This still doesn't all the Create part of CRUD though, right? I can only create a new entity in a workspace if it `isEntityTypeSupported` which has to pass this check:

    $supported = !is_a($entity_type->getHandlerClass('workspace'), IgnoredWorkspaceHandler::class, TRUE);

    So RUD operations seems to be more accurate.

  • πŸ‡·πŸ‡΄Romania amateescu

    You can create paragraph entities in a workspace if you have WSE installed or this patch, but they're not tracked by that workspace :) The CRUD part mostly means "allow any operation for this entity type but don't track it".

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    @amateescu, thanks for the quick reply!

    The error I'm seeing is "Paragraphs can only be created in the default workspace.", which is coming from the WseEntityReferenceSupportedNewEntitiesConstraint, though the core one would flag this as well.

    The key checks are...

    From core:

    if ($value->hasNewEntity() && !$this->workspaceInfo->isEntityTypeSupported($target_entity_type)) {
          $this->context->addViolation($constraint->message, ['%collection_label' => $target_entity_type->getCollectionLabel()]);
        }

    From WSE:

    if ($value->hasNewEntity() && !$target_entity_type->isInternal() && !\Drupal::service('workspaces.information')->isEntityTypeSupported($target_entity_type)) {
          $this->context->addViolation($constraint->message, ['%collection_label' => $target_entity_type->getCollectionLabel()]);
        }
    

    I guess the situation is that I could create a Paragraph in a Workspace if I somehow do it without using the Paragraphs field widget. So technically, CRUD is allowed, but in practice creating a Paragraph is going to throw this constraint validation.

    On my client's project, I could do a field_info_alter to remove this constraint from paragraph fields. But is this in fact a bug in the validation constraint?

  • πŸ‡ΊπŸ‡ΈUnited States danflanagan8 St. Louis, US

    I decided to open up an issue against wse so that I could put in an MR to adjust the constraint. ✨ Modify constraint to allow new ignored entities Active

Production build 0.71.5 2024