Problem/Motivation

When you have a content type that is using workflows / content moderation, revisions, workbench_email, and the trash module enabled, an error happens when trying to move an item into the trash bin.

TypeError: Drupal\content_moderation\ModerationInformation::isModeratedEntity(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/web/modules/contrib/workbench_email/workbench_email.module on line 118

Steps to reproduce

  1. Create a content type, a workflow, and assign the content type to the workflow.
  2. Enable workbench Email and Trash module.
  3. Create a new piece of content. State (published, draft, etc). does not matter.
  4. Try to delete the content, evoking the Trash module to move it into trash rather than actually deleting it.
  5. Error happens.

Proposed resolution

The problem is that on line 110 of workbench_email.module, the entity coming back when it intercepts during the Trash moving process isn't a typeof EntityInterface. I propose having a check to make sure that what is loaded is of that type.

I have created a patch file to help with this.

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

cozydrupalnerd created an issue. See original summary.

cozydrupalnerd’s picture

StatusFileSize
new855 bytes

larowlan’s picture

sounds like this might need to run _before_ trash module?

no sssweat’s picture

@larowlan I tried making the Trash module have higher weight, but that didn't work. Error still thrown.

no sssweat’s picture

Status: Active » Reviewed & tested by the community

Considering the _workbench_email_content_moderation_event_shim function never gets called unless the Trash module is installed, the proposed solution seems valid to me.

Patch applied fine as expected.

dasginganinja’s picture

Any chance of this issue making it into the next tagged release? Please and thanks.

larowlan’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Considering the _workbench_email_content_moderation_event_shim function never gets called unless the Trash module is installed, the proposed solution seems valid to me.

This is not correct, this event is how the module works. It doesn't fire if you've patched core for #2873287: Dispatch events for changing content moderation states.

The concern here is that content_moderation is creating a moderation state entity that points to a revision that can't be loaded from the database. Does that point to a referential integrity issue w/ content_moderation + trash?

Can we get a backtrace here to understand where/how this is happening?

inregards2pluto’s picture

I can confirm that we're getting the same issue when we try to delete content with the Trash, Workbench Email, and Content Moderation modules installed on a D11.2 site.

The error message is:
TypeError: Drupal\content_moderation\ModerationInformation::isModeratedEntity(): Argument #1 ($entity) must be of type Drupal\Core\Entity\EntityInterface, null given, called in /var/www/html/web/modules/contrib/workbench_email/workbench_email.module on line 115 in Drupal\content_moderation\ModerationInformation->isModeratedEntity() (line 51 of /var/www/html/web/core/modules/content_moderation/src/ModerationInformation.php).

And the full Back Trace is in the attached file. It was on the long side and I'm admittedly not sure what best practice is on d.o. for sharing full back traces, so I figured the file was the best bet.

inregards2pluto’s picture

I tried using the following OOP hooks to have the entity_update/entity_insert hooks fire before the Trash module hooks to see if that would work (per core release notes from last year):

<?php

namespace Drupal\workbench_email\Hook;

use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Hook\Attribute\Hook;
use Drupal\Core\Hook\Attribute\ReorderHook;
use Drupal\Core\Hook\Order\OrderAfter;
use Drupal\Core\Hook\Order\OrderBefore;

#[ReorderHook('entity_insert',
  class: WorkbenchEmailHooks::class,
  method: 'entityInsert',
  order: new OrderAfter(['content_moderation'])
)]
#[ReorderHook('entity_insert',
  class: WorkbenchEmailHooks::class,
  method: 'entityInsert',
  order: new OrderBefore(['trash'])
)]
#[ReorderHook('entity_update',
  class: WorkbenchEmailHooks::class,
  method: 'entityUpdate',
  order: new OrderAfter(['content_moderation'])
)]
#[ReorderHook('entity_update',
  class: WorkbenchEmailHooks::class,
  method: 'entityUpdate',
  order: new OrderBefore(['trash'])
)]
class WorkbenchEmailHooks {

  #[Hook('entity_insert')]
  public function entityInsert(EntityInterface $entity): void {
    _workbench_email_process_if_moderated($entity);
  }

  #[Hook('entity_update')]
  public function entityUpdate(EntityInterface $entity): void {
    _workbench_email_process_if_moderated($entity);
  }

}

However, like mentioned in comment #5, that alone doesn't fix the issue.

The OG patch DOES resolve the issue and I'm able to move moderated content to and from the Trash.