This module breaks Drupal core workflow add form

Created on 3 June 2025, 4 months ago

Problem/Motivation

If this module is installed then it's impossible to add a content moderation workflow.

Steps to reproduce

  1. Go to Admin → Configuration → Workflow → Workflows.
  2. Click '+ Add workflow'.
  3. Error occurs:

The website encountered an unexpected error. Try again later.

Error: Call to a member function get() on null in Drupal\workflows\Entity\Workflow->getTypePlugin() (line 121 of core/modules/workflows/src/Entity/Workflow.php).

content_moderation_entity_access()
call_user_func_array() (Line: 416)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}() (Line: 395)
Drupal\Core\Extension\ModuleHandler->invokeAllWith() (Line: 415)
Drupal\Core\Extension\ModuleHandler->invokeAll() (Line: 100)
Drupal\Core\Entity\EntityAccessControlHandler->access() (Line: 329)
Drupal\Core\Entity\EntityBase->access() (Line: 33)
commerce_license_entity_field_form_alter() (Line: 552)

Proposed resolution

The issue is here in core content_moderation_entity_access():

if ($entity instanceof WorkflowInterface) {
  $configuration = $entity->getTypePlugin()->getConfiguration();
  // ... [snip]
}

In this case $entity is a blank Workflow entity and getTypePlugin() looks like this:

public function getTypePlugin() {
  return $this->getPluginCollection()->get($this->type);
}

Therefore getPluginCollection() returns null because there is no plugin - there is no workflow yet. So it calls get() on null.

The issue arises because commerce_license_entity_field_form_alter() triggers an access check on the $entity:

$entity = $form_object->getEntity();
// ... [snip]
// Don't bother doing anything if the user can't delete the entity anyway.
if (!$entity->access('delete')) {
  return;
}

Proposed resolution

The function can exit early if the entity doesn't exist:

if (!$entity->id()) {
  return;
}

This resolves the problem. Since this function only cares about the delete action, it doesn't ever need to care about a non-existent entity.

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom Rob230

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024