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)

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.

CommentFileSizeAuthor
#4 3528221-this-module-breaks-4.patch931 bytesrob230
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

rob230 created an issue. See original summary.

rob230’s picture

Issue summary: View changes

rob230’s picture

StatusFileSize
new931 bytes

Patch

rob230’s picture

Status: Active » Needs review
rob230’s picture

Status: Needs review » Reviewed & tested by the community

Have used this for a while, merging.

  • rob230 committed 71ed985a on 8.x-2.x
    Issue #3528221 by rob230: This module breaks Drupal core workflow add...
rob230’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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