Problem/Motivation
If this module is installed then it's impossible to add a content moderation workflow.
Steps to reproduce
- Go to Admin → Configuration → Workflow → Workflows.
- Click '+ Add workflow'.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | 3528221-this-module-breaks-4.patch | 931 bytes | rob230 |
Issue fork commerce_license_entity_field-3528221
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
Comment #2
rob230 commentedComment #4
rob230 commentedPatch
Comment #5
rob230 commentedComment #6
rob230 commentedHave used this for a while, merging.
Comment #8
rob230 commented