Allow opting out entity types and bundles from workflows

Created on 10 March 2023, over 1 year ago
Updated 17 April 2023, over 1 year ago

Problem/Motivation

This is basically a followup to ✨ Prompt users to activate a workspace in the content workflow instead of just denying access to some page Fixed . The logic in the new RouteEnhancer inside the entity_workflow_content would allow us to exclude certain bundles or entire entity types from workflows and the requirement to choose a workspace before an edit or adding an entity. To exclude a type/bundle, hook_entity_workflow_type_alter() can be implemented to manipulate $configuration['entity_types'] by removing bundles or entity types.

Unfortunately this doesn't work yet because of the following code in EntityWorkflowTypeBase::setConfiguration():

    if ($this->configuration['entity_types'] != $this->defaultConfiguration()['entity_types']) {
      throw new \DomainException('The supported entity types for an entity workflow plugin can not be changed.');
    }

Steps to reproduce

On vanilla Drupal

  1. Enable entity_workflow and wse modules
  2. In a custom module implement the code below
  3. Try to add a node of type article

Proposed resolution

Remove the condition and throwing of the exception in EntityWorkflowTypeBase::setConfiguration() mentioned above completely or override setConfiguration only in relevant WorkflowType plugins, not throwing the exception.

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

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

Comments & Activities

  • Issue created by @s_leu
  • @s_leu opened merge request.
  • Status changed to Needs review over 1 year ago
    • s_leu β†’ committed 3faafd42 on 2.x
      Issue #3347119: Dropped condition that compares altered config's entity...
  • Status changed to Fixed over 1 year ago
  • πŸ‡·πŸ‡΄Romania amateescu

    Merged into 2.x, thanks!

  • Status changed to Needs work over 1 year ago
  • Re-opening this because there's yet a problem with excluding certain bundles or entire entity types from workflows via hook_entity_workflow_type_alter() and manipulating $configuration['entity_types'] to remove bundles or entire entity types from a workflow.

    The problem seems to be that the RouteEnhancer is not really checking the possibly altered workflow config. In RouteEnhancer::enhance() the only check that happens is if a bundle/entity type is part of a workflow by calling EntityWorkflowInfo::getWorkflowsInfoForEntityTypeAndBundle() or EntityWorkflowInfo::getWorkflowsInfoForEntityType($entity_type_id). Thus, this code gets all bundles/entity types regardless of whether they are β€œaltered out” via hook_entity_workflow_type_alter() or not.

    To solve this we need to check the actual workflow configuration that is possibly altered. I'm not sure whether this should happen inside the route enhancer or not, but I'm adding it there for now. I can still move it if it makes more sense to have this inside EntityWorkflowInfo but as I'm not completely familiar with this module it could have unwanted side effects which I'm unaware of to add it there.

  • @s_leu opened merge request.
  • Status changed to Needs review over 1 year ago
  • πŸ‡·πŸ‡΄Romania amateescu

    Merged the followup into 2.x, thanks!

  • Status changed to Fixed over 1 year ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024