Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When there are existing nodes of a particular type, and then you enable moderation for that node type, you then get a fatal error upon saving a new draft of the existing content:
Fatal error: Call to a member function label() on a non-object in /var/www/moderation.local/web/modules/workbench_moderation/src/Plugin/Validation/Constraint/ModerationStateValidator.php on line 78
To duplicate:
* On a fresh install, create an article "Foo"
* Enable moderation for the article content type
* Edit the article "Foo"
* --> see the error
Comment | File | Size | Author |
---|---|---|---|
#3 | existing-content.patch | 4.74 KB | Crell |
Comments
Comment #2
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedHave verified with a test, will post a fix shortly.
Comment #3
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedAnd here's the patch with test. Took a while to figure out the right kind of test, but this works. :-)
(Code is also in the existing-content branch.)
Comment #4
becw CreditAttribution: becw at Palantir.net for Acquia commentedSo this validation doesn't check whether the given moderation state is available based on the bundle moderation config, does it? Just whether the transition exists.
This isn't new though :)
Maybe use
$this->randomMachineName()
and$this->randomString()
.This patch fixes the issue described in the ticket.
However, have you tried disabling workbench moderation on content with a forward revision? This leads to an unrelated (non-validator) issue, which I will hassle you about elsewhere.
Comment #5
Crell CreditAttribution: Crell at Palantir.net for Acquia commentedWhether the transition is allowed or not is determined by StateTransitionValidation. Its logic doesn't change here. It looks like you're correct, it's not validating that the destination state is legal for the entity in question. I don't know if we should fix that here or elsewhere. I'm thinking elsewhere, as there's other cleanup that StateTransitionValidation desperately needs, unless the fix for it would be done in the method we're already modifying here... (The way StateTransitionValidation is wired to the container is so wrong it's painful.)
Is there an advantage to using random strings for the machine names instead of a known human-friendly string? I am always highly skeptical about the word "random" anywhere near a test class. (I also copied that code from elsewhere in the same class, so we're already using a static string.)
Comment #6
becw CreditAttribution: becw at Palantir.net for Acquia commentedYeah, using 'example' is... fine, it just increases the chance of collisions.
Comment #8
becw CreditAttribution: becw at Palantir.net for Acquia commented