Problem/Motivation

The 'Change State' form has an error: The website encountered an unexpected error. Please try again later.

Error Log
TypeError: Argument 1 passed to Drupal\content_moderation\Form\EntityModerationForm::__construct() must implement interface Drupal\content_moderation\ModerationInformationInterface, instance of Drupal\Core\Entity\EntityRepository given, called in /var/www/html/docroot/modules/contrib/content_moderation_info_block/src/Form/ContentModerationInfoBlockForm.php on line 45 in Drupal\content_moderation\Form\EntityModerationForm->__construct() (line 53 of /var/www/html/docroot/core/modules/content_moderation/src/Form/EntityModerationForm.php)

Steps to reproduce

Enable form
Change state

Comments

oktboy created an issue. See original summary.

ankitv18’s picture

Assigned: Unassigned » ankitv18
ankitv18’s picture

StatusFileSize
new6.95 KB

Adding patch for state form issues fix while placing the block.
This patch handles the argument error issue with the form.

ankitv18’s picture

Assigned: ankitv18 » Unassigned
Status: Active » Needs review
pratik_kamble’s picture

Assigned: Unassigned » pratik_kamble
ankitv18’s picture

Assigned: pratik_kamble » ankitv18
Status: Needs review » Active
StatusFileSize
new7.48 KB
new7.48 KB

Adding patch for state form issues fix while placing the block.
This patch handles the dependency injection error issue within the form.

Please review this patch #6 and give the feedback

ankitv18’s picture

ankitv18’s picture

StatusFileSize
new7.48 KB
new7.48 KB

Adding patch for state form issues fix while placing the block.
This patch handles the dependency injection error issue within the form.

Please review this patch #8 and give the feedback

ankitv18’s picture

Assigned: ankitv18 » Unassigned
Status: Active » Needs review
joel_osc’s picture

@Ankitv18 thank-you for the patch! The fix is working, but the patch failed to apply for me so I had to do one chunk manually:

Hunk #1 succeeded at 2.
Hunk #2 succeeded at 18.
Hunk #3 succeeded at 60.
Hunk #4 FAILED at 96.
Hunk #5 succeeded at 124 (offset -4 lines).
1 out of 5 hunks FAILED
@@ -94,10 +100,8 @@ class ContentModerationInfoBlockForm extends EntityModerationForm {
       return $form;
     }

-    $this->setEntity($entity);
-    $this->setOperation('moderate');
     $form_state->set('entity', $entity);
-    $form = parent::buildForm($form, $form_state);
+    $form = parent::buildForm($form, $form_state, $entity);

I cannot figure out why though - the patch seems fine.

rp7’s picture

Status: Needs review » Postponed (maintainer needs more info)

Is this issue still present? Which Drupal version are you using? I'm afraid the module is incorrectly advertising compatibility with Drupal 8.

jstoller’s picture

Version: 8.x-1.0-beta4 » 2.0.0-beta1
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new5.94 KB

This is still an issue with Drupal 9.5.11 and Content Moderation Info Block 2.0.0-beta1. I've updated the patch from #8 so it applies to the latest version.

jeni_dc’s picture

Status: Needs review » Reviewed & tested by the community

Patch from #12 applied cleanly for me on 2.0.0-beta1 and the error is now gone. The block shows as expected.

rp7’s picture

Looks like this same issue was also raised in #3263108: ContentModerationInfoBlockForm - Fatal Error.

I see what's going on here. Apparently I've been developing this against the patch @ #2849279: Make the moderation control form an entity form so that it validates entities before save.

I will need to look deeper into a way forward.

rp7 credited firewaller.

rp7 credited kerasai.

rp7’s picture

rp7’s picture

Title: State Form Error » Fix ContentModerationInfoBlockModerationForm constructor

  • rp7 committed 5405341f on 2.0.x
    Issue #3185894 by ankitv18, jstoller, rp7, kerasai, firewaller: Fix...
rp7’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.