Problem/Motivation

Developers should have the option to allow specified entities to be ignored by Workspaces.

For example, it's desirable to allow the manipulation of file and crop entities in a workspace without tracking them, or to ignore non-reusable blocks.

Proposed resolution

Add the concept of workspace handlers (similar to the moderation handler provided by the Content Moderation module), that are in charge of determining if an entity should be tracked, ignored or forbidden in a workspace.

Issue fork drupal-3101671

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Donnyboypony created an issue. See original summary.

smithmilner’s picture

StatusFileSize
new5.57 KB

This patch gives me the ability to define skippable entity types in a custom module with a service decorator.

Example:

foo_workspaces.services.yml

services:
  foo_workspaces.manager:
    class: Drupal\foo_workspaces\FooWorkspaceManager
    decorates: workspaces.manager
    parent: workspaces.manager

FooWorkspaceManager.php

<?php

namespace Drupal\foo_workspaces;

use Drupal\workspaces\WorkspaceManager;

/**
 * Provides the Foo workspace manager.
 */
class FooWorkspaceManager extends WorkspaceManager {

  /**
   * An array of entity type IDs that should not be processed by workspaces
   * while at the same time in non-default workspaces.
   *
   * Changes to these entities will leak into the live site.
   *
   * @var string[]
   */
  protected $skiplist = [
    'file' => 'file',
    'crop' => 'crop',
  ];

}

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
dspachos’s picture

I tested and seems to work well!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

s_leu’s picture

Status: Active » Needs review
ranjith_kumar_k_u’s picture

StatusFileSize
new6.17 KB

Rerolled #2 for 9.5

s_leu’s picture

I'm not sure if the proposed solution here actually makes sense. There is already an existing solution to enable/support entity types in, which are not publishable and revisionable, in workspaces by marking them as internal, see #3027598: Omit workspaces entity presave and predelete hooks for internal entities.

Given that possibility It feels relatively cumbersome to override the workspace manager just to allow some entity type to be handled inside workspaces, when compared to implementing hook_entity_type_alter() and marking an existing entity type as internal in a custom module, or even marking a custom entity type as internal right via the internal flag of the entity type annotation. IMO this feels much lighter than overriding a core service to support an entity type, so I'd personally close this as a won't fix.

s_leu’s picture

Status: Postponed » Needs work

If going for a solution like the one proposed here, I'd suggest to expose supported entity types via config or even on a settings form instead of hardcoding this inside an overridden service.

We already have something similar in place for config entity, which are supported via the wse_config submodule of the workspaces extra module. The corresponding code can be found here: https://git.drupalcode.org/project/wse/-/blob/1.0.x/modules/wse_config/w...

amateescu’s picture

Version: 9.4.x-dev » 10.1.x-dev
Priority: Normal » Major
Status: Needs work » Needs review
Issue tags: +WI critical, +Needs tests
StatusFileSize
new54.16 KB

There is already an existing solution to enable/support entity types in, which are not publishable and revisionable, in workspaces by marking them as internal

Marking entity types as internal is just a temporary workaround until a proper API was created in this issue :) Also, it doesn't really work in all cases, see #3058224-3: Allow CRUD operations for Crop entities in a workspace

After getting more experience with how Workspaces is used in production sites, my proposal is to add four "workspace support states":

  • unsupported - workspace processing throws an exception (e.g. non-revisionable entities, config entities)
  • ignored - workspace processing allows pass-through (e.g. entities that don't affect the live site; e.g. paragraph, crop, file?)
  • supported - workspace processing does its job for every entity of this type
  • supported on per-entity basis - workspace processing needs to ask each entity if it's supported (e.g. non-reusable blocks)

These support states will come in a new workspace_information service, which would deprecate WorkspaceManagerInterface::isEntityTypeSupported(), ::getSupportedEntityTypes() and shouldAlterOperations().

Here's a patch based on the proposal above. Still needs test coverage for new service, but the code itself is ready for review.

Status: Needs review » Needs work

The last submitted patch, 12: 3101671-12.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new54.16 KB
new746 bytes

Oops :)

Status: Needs review » Needs work

The last submitted patch, 14: 3101671-14.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new54.17 KB
new736 bytes

Fixed that last fail.

Status: Needs review » Needs work

The last submitted patch, 16: 3101671-16.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative

Will this still need tests?

Could new functions be typehinted?

Didn't do a full code review (not as familar with workspaces)

amateescu’s picture

Assigned: Unassigned » amateescu
StatusFileSize
new54.85 KB

Rolled this patch on top of #3092247: Prevent content from being deleted when there is an active workspace, for those who need it.

This definitely still needs some test coverage, I'll look into that next.

amateescu’s picture

StatusFileSize
new54.79 KB

Same patch as above, for who needs it to apply against Drupal 9.5.x.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

cedricl’s picture

For drupal core 9.5.x i'm getting
Cannot apply patch https://www.drupal.org/project/drupal/issues/3101671#comment-14976504 (https://www.drupal.org/files/issues/2023-03-21/3101671-21-against-deletable-9.5.x.patch)!
Any fixes for this issue. I also applied the patches from #22

rpayanm made their first commit to this issue’s fork.

amateescu’s picture

@CedricL, see comment #22, you also have to apply two other patches before this one.

amateescu’s picture

StatusFileSize
new54.45 KB

Rerolled #16 on top of latest 11.x.

amateescu’s picture

StatusFileSize
new54.26 KB
new10.47 KB

Updated to the latest coding standards. Leaving at NW for adding test coverage.

amateescu’s picture

StatusFileSize
new57.46 KB
new3.45 KB

Fixed a few deprecated usages.

webdrips’s picture

StatusFileSize
new47.81 KB

Reroll #30 for 10.2.2, but would expect it to work on 11.x based on the minor change.

webdrips’s picture

Hiding last patch, as it missed a directory

webdrips’s picture

StatusFileSize
new57.45 KB

Trying this again as the last patch missed a directory.

webdrips’s picture

Even with the updated patch plus #3092247-62: "[PP-1] Prevent content from being deleted when there is an active workspace", I'm not able to upload images in the non-default workspace.

I get the following error via Ajax:

Drupal\Core\Entity\EntityStorageException: This entity can only be saved in the default workspace. in Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php). workspaces_entity_presave(Object)
call_user_func_array(Object, Array) (Line: 409)
Drupal\Core\Extension\ModuleHandler-&gt;Drupal\Core\Extension\{closure}(Object, &#039;workspaces&#039;) (Line: 388)
Drupal\Core\Extension\ModuleHandler-&gt;invokeAllWith(&#039;entity_presave&#039;, Object) (Line: 416)
Drupal\Core\Extension\ModuleHandler-&gt;invokeAll(&#039;entity_presave&#039;, Array) (Line: 217)
Drupal\Core\Entity\EntityStorageBase-&gt;invokeHook(&#039;presave&#039;, Object) (Line: 900)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;invokeHook(&#039;presave&#039;, Object) (Line: 529)
Drupal\Core\Entity\EntityStorageBase-&gt;doPreSave(Object) (Line: 753)
Drupal\Core\Entity\ContentEntityStorageBase-&gt;doPreSave(Object) (Line: 483)
Drupal\Core\Entity\EntityStorageBase-&gt;save(Object) (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage-&gt;save(Object) (Line: 352)
Drupal\Core\Entity\EntityBase-&gt;save() (Line: 293)
Drupal\file\Upload\FileUploadHandler-&gt;handleFileUpload(Object, Array, &#039;public://hero_images/&#039;, 0) (Line: 658)
file_save_upload(&#039;field_content_hero_0_subform_field_hero_image_0&#039;, Array, &#039;public://hero_images&#039;, NULL, 0) (Line: 536)
_file_save_upload_from_form(Array, Object) (Line: 1007)
file_managed_file_save_upload(Array, Object) (Line: 76)
Drupal\file\Element\ManagedFile::valueCallback(Array, Array, Object) (Line: 337)
Drupal\file\Plugin\Field\FieldWidget\FileWidget::value(Array, Array, Object)
call_user_func_array(Array, Array) (Line: 1266)
...
amateescu’s picture

Assigned: amateescu » Unassigned
Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new68.77 KB
new32.85 KB

@webdrips this patch only adds the possibility to "ignore" entity types in a workspace, it doesn't yet do it for the File entity type. That will probably happen in #3025785: Cannot create entity with image in a workspace.

Here's a fairly extensive update after using this patch in production for several years. The problem with the initial approach (using constants on WorkspaceInformationInterface) was that an entity type could not declare its workspace support when the Workspaces module wasn't installed, since the interface couldn't be loaded, so we're now using explicit entity handlers for supported and ignored entity types. Entity handlers can point to a non-existent class, because the class won't be loaded until someone tries to instantiate that handler.

Also added test coverage, so removing the tag. I'll convert the patch to a MR, then it should be fully ready for reviews!

amateescu changed the visibility of the branch 11.x to hidden.

amateescu changed the visibility of the branch 3101671-11.x to hidden.

amateescu’s picture

Issue summary: View changes

Updated the issue summary and hid all the patches because we have an MR now.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs change record updates

Made a few suggestions but they can apply to a number of the files.

But is there BC concerns for marking previously not internal files as internal? I don't know the policy around that.

amateescu’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record updates

@smustgrave, thanks for reviewing! Fixed your suggestions, and after scanning the code again for similar changes that could be done to other constructors, I think I would prefer to "modernize" them all in a separate issue.. this MR is already big enough IMO.

Updated the CR as well.

FWIW, this is the #1 issue in the (somewhat short) list of blockers for marking Workspaces as stable, which I hope we can do in 10.3 :)

amateescu’s picture

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Changes look good and test updates. CR reads well

  • catch committed 1fd6c15a on 10.3.x
    Issue #3101671 by amateescu, webdrips, smithmilner, s_leu, smustgrave:...

  • catch committed 940a0690 on 11.x
    Issue #3101671 by amateescu, webdrips, smithmilner, s_leu, smustgrave:...
catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

Adding a handler is a good idea, and the entity type/entity split handles block content entities nicely - flexibility but without a lot of messing about for entity types that don't need it.

Committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.