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
- Create a content type, a workflow, and assign the content type to the workflow.
- Enable workbench Email and Trash module.
- Create a new piece of content. State (published, draft, etc). does not matter.
- Try to delete the content, evoking the Trash module to move it into trash rather than actually deleting it.
- 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | workbench-email--issue-3515843-backtrace.txt | 10.1 KB | inregards2pluto |
| #2 | workbench-email-issue-3515843-02.patch | 855 bytes | cozydrupalnerd |
Issue fork workbench_email-3515843
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
cozydrupalnerd commentedComment #4
larowlansounds like this might need to run _before_ trash module?
Comment #5
no sssweat commented@larowlan I tried making the Trash module have higher weight, but that didn't work. Error still thrown.
Comment #6
no sssweat commentedConsidering the
_workbench_email_content_moderation_event_shimfunction never gets called unless the Trash module is installed, the proposed solution seems valid to me.Patch applied fine as expected.
Comment #7
dasginganinjaAny chance of this issue making it into the next tagged release? Please and thanks.
Comment #8
larowlanThis 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?
Comment #9
inregards2plutoI 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.
Comment #10
inregards2plutoI 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):
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.