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();
Files: 
CommentFileSizeAuthor
#5 2871627-5.patch1.61 KBtimmillwood

Comments

keboca created an issue. See original summary.

timmillwood’s picture

Project: Drupal core » RNG - Events and Registrations
Version: 8.3.0 » 8.x-1.x-dev
Component: content_moderation.module » Code

Why 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, so Drupal\content_moderation\Plugin\Field\FieldWidget\ModerationStateWidget::processActions should never get called.

This sounds like an issue with RNG or the configuration of RNG.

dpi’s picture

Title: Content Moderation and RNG throw an exception » Content Moderation widget gets entity incorrectly
Project: RNG - Events and Registrations » Drupal core
Version: 8.x-1.x-dev » 8.3.x-dev
Component: Code » content_moderation.module

RNG 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.

dpi’s picture

Issue summary: View changes
timmillwood’s picture

Version: 8.3.x-dev » 8.4.x-dev
Status: Active » Needs review
Issue tags: +Workflow Initiative
FileSize
1.61 KB

Here's a patch for this.

This will be a non-issue once #2753717: [PP-1] Add select field to choose moderation state on entity forms is in.