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.
I have installed the Content Moderation module and I have applied the default workflow to one node type.
If I create a new node (without moderation), I got the following error when trying to save it:
PHP Fatal error: Call to a member function getTypePlugin() on a non-object in /var/www/html/drupal8/core/modules/content_moderation/src/Plugin/Field/ModerationStateFieldItemList.php on line 156,
If I reopen the page and if I fill everything except the image field, then everything is fine.
But if I upload an image into the image field (with the image_crop_widget) then I get the fatal error described upper. (really strange isn't it)
Comment | File | Size | Author |
---|---|---|---|
#18 | 2900687-18.patch | 4.18 KB | timmillwood |
#14 | 2900687-14.patch | 4.18 KB | Sam152 |
#14 | 2900687-14--test-only.patch | 2.42 KB | Sam152 |
#13 | 2900687-13.patch | 1.76 KB | Sam152 |
#10 | 2900687-8.patch | 6.16 KB | timmillwood |
Comments
Comment #2
DuneBLHere is a small patch that solve/fix this issue... But I think we should dig more deeply because I don't understand why
updateModeratedEntity($moderation_state_id)
is called fromwithin a content type that doesn't play with moderation.Comment #3
tacituseu CreditAttribution: tacituseu commentedcore/modules/content_moderation/src/EntityTypeInfo::entityBaseFieldInfo()
is adding the computed field per entity type (not per bundle/content type), so all node bundles (content types) have it.Makes sense to check
ModerationInformation::getWorkflowForEntity()
return value.Comment #4
tacituseu CreditAttribution: tacituseu commentedComment #5
timmillwoodGood find!
I've just been able to replicate this, and as you say, it only happens when adding a file.
Comment #6
timmillwoodI think I'd fix it like this.
Although it's weird it only happens when a file is added, I think that needs further investigation.
Comment #7
larowlanWe need a test here, but I'm guessing it is something to do with ajax/serialized form state
Comment #8
timmillwoodI wrote a test for this, but it passes even without the fix.
When trying to find out why that is I noticed the issue is only reproducible with JavaScript enabled. So looks like we need a JavaScript test to cover this. 😢
Comment #10
timmillwoodLooks like I deleted too much in the test-only patch, let's try that again.
Although I'm expecting both patches to pass.
Comment #11
timmillwoodok, as I thought, both are passing. So need a JS test, should be able to copy a lot of
\Drupal\Tests\image\FunctionalJavascript\QuickEditImageTest
but with Content Moderation.Not sure it's worth keeping the extra testing in #9/#10?
Comment #12
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedFix looks good, but I was keen to see what the root cause of this was. Why do we have a FieldItem on our custom FieldItemList for an entity that isn't being moderated? Findings below:
#access => false
it's still considered part of the form and all of the wrapping form elements still exist. The line of code which trips things up is in \Drupal\Core\Field\WidgetBase::formMultipleElements:It creates a field item for us, so that the widget element can be rendered (remember writing widgets you are given
$items
and$delta
and you always have some FieldItem for$items[$delta]
?WidgetBase
is usually super helpful and tries to filter out empty items in::extractFormValues
:...BUT since this code is guarded by checking if the actual item is in
$form_state
(which it's not cause the widget is hidden), it gets skipped:Hence I think fixing the root cause would involve making sure our widget calls
filterEmptyItems
in such a way that isn't dependent on the form_state having a value for the field.Comment #13
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedI wonder if it would be better to avoid this situation with some tweaks in our widget. Not starting the process of building the widget form seems to fix this for me. Lets see what testbot says.
I'd say things are going to be more stable if we never have the situation of
$not_moderated_entity->moderation_state
having a value.Comment #14
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedComment #16
timmillwoodGreat investigating @Sam152!
Simple patch, and nice test.
Comment #17
catchNeeds a re-roll.
Comment #18
timmillwoodComment #21
catchCommitted/pushed to 8.5.x and cherry-picked to 8.4.x. Thanks!
Comment #22
prestonso CreditAttribution: prestonso commentedTagging for inclusion in 8.4.0-beta1 release notes.
Comment #23
Sam152 CreditAttribution: Sam152 as a volunteer and at PreviousNext commentedDoes this belong in the release notes if it didn't exist in 8.3? I believe it was introduced in #2753717: Add select field to choose moderation state on entity forms which was committed to 8.4.