Problem/Motivation
Currently we add a base field to entity types and then hide the moderation_state widget if the specific entity we are editing isn't being moderated. Some bundles may have moderation switched off. The way we do this is with a check in our widget, but this doesn't protect other widgets and can cause a fatal with the following steps:
drush si standard && drush en content_moderation- Edit the Article form display, change the widget to "Textfield".
- Save any article, see a fatal.
Proposed resolution
Use field access for controlling if the field should appear or not.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | 2915384-7.patch | 2.04 KB | sam152 |
| #2 | 2915384-2.patch | 2.19 KB | sam152 |
Comments
Comment #2
sam152 commentedThis should do it and I suppose it also fixes the problem for REST.
Comment #4
sam152 commentedLooks like
\Drupal\Core\Entity\Entity\EntityFormDisplay::extractFormValuesstill tries to initialise themoderation_statefield because it somehow still exists in the$form_statedespite is having access denied. I suspect somewhere in core, the widget is built into the form, then#access => falseis applied.A few options are to:
$entity->moderation_state = ''fail more gracefully on non-moderated bundles.EntityFormDisplayto not set the field if there is no access to it.Comment #7
sam152 commentedReroll, can still reproduce this.
Comment #18
larowlan