Problem/Motivation
Hi guys, I noticed that content moderation module throws an exception when I have enabled RNG module at same time.
I was unsure where to report this issue, then I reported into RNG project here:
https://github.com/dpi/rng/issues/142
Basically it's throwing this expception:
Error: Call to undefined method Drupal\rng\Form\EventSettingsForm::getEntity() in Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget::processActions() (line 183 of core/modules/content_moderation/src/Plugin/Field/FieldWidget/ModerationStateWidget.php).
Original report
Because "ModerationStateWidget::processActions" is executing a chaining methods, like this:
$entity = $form_state->getFormObject()->getEntity();
Since "EventSettingsForm" is a configuration form that won't be publish or unpublish, I believe that we should setup a validation into "processActions" method:
if(!method_exists($form_state->getFormObject(), 'getEntity')) {
return;
}
$entity = $form_state->getFormObject()->getEntity();
Steps to reproduce
1. Enable content moderation and rng module
2. Go to Event types(i.e. /admin/structure/rng/event_types)
3. Add new event type.
4. Select "use existing bundle" and select "Article" under the dropdown.
5. Create a new article
6. Visit the "event" tab of the article.
Expected:
- See available events
Actual:
- Fatal error.
Proposed resolution
Remaining tasks
Review
Comment | File | Size | Author |
---|---|---|---|
#7 | 4.2871627-fatal-error-fixed.png | 267.08 KB | vijaycs85 |
#7 | 3.2871627-fatal-error.png | 960.15 KB | vijaycs85 |
#7 | 2.2871627-event-tab.png | 91.75 KB | vijaycs85 |
#7 | 1.2871627-event-type.png | 242.82 KB | vijaycs85 |
#5 | 2871627-5.patch | 1.61 KB | timmillwood |
Comments
Comment #2
timmillwoodWhy does this form has a moderation_state widget on it anyway?
It doesn't look to be a content entity form as it doesn't extent
ContentEntityForm
, soDrupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget::processActions
should never get called.This sounds like an issue with RNG or the configuration of RNG.
Comment #3
dpiRNG uses entity form display modes, which is why the error is showing.
ModerationStateWidget
is making assumptions that the root form always extends `\Drupal\Core\Entity\EntityForm`. It is trying to grab the entity of the root form.ModerationStateWidget
should instead grab the entity from\Drupal\Core\Field\FieldItemListInterface::getEntity()
, which will get the proper entity regardless of which dimension the entity form is attached to.Unfortunately process callbacks dont have access to the original field list object, so its going to be tricky to do this.
This is not a problem of RNG. I expect other consumers of entity form displays, like inline_entity_form?, will come across this issue.
Comment #4
dpiComment #5
timmillwoodHere's a patch for this.
This will be a non-issue once #2753717: Add select field to choose moderation state on entity forms is in.
Comment #6
timmillwood@keboca - Does this fix your issue?
Comment #7
vijaycs85Tested the patch in #5 by following steps to reproduce and patch fixes the issue.
Comment #8
timmillwoodI wondered if this needs tests, but equally don't think we need to bother as #2753717: Add select field to choose moderation state on entity forms will remove this widget.
Comment #9
Gábor HojtsyWell, #2753717: Add select field to choose moderation state on entity forms has been "almost done" for a while, so I think it would be important to not add untested code assuming that lands soon, while we have been assuming that for a while. Either this needs tests or can be marked duplicate of that IMHO.
Comment #10
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedI vote for not wasting time if #2753717: Add select field to choose moderation state on entity forms is where we want to go in the end :)