Sorry if I'm posting this issue in the wrong place, but I was only able to fix the problem on Core level as you can see it in the patch.

Reproduce

  1. Install the Paragraphs with composer and enable it.
  2. Install Inline Entity Form module with composer and enable it.
  3. Apply the patch from https://www.drupal.org/project/inline_entity_form/issues/3015323, patch: https://www.drupal.org/files/issues/2018-11-26/3015323-3.patch
  4. Enable the core Workflows module.
  5. Create a basic Paragraph type (Paragraph Test).
  6. Create a new content type (Bar) with a Paragraph field (Paragraph field) that uses the previously created paragraph type (Paragraph Test) set it not to be required.
  7. Create a new content type (Foo) with a Reference field (Inline form), referencing the previously created content type (Bar).
  8. Choose the 'Inline Entity Form - Complex' widget for the field (Inline form), in the Form display page.
  9. Create a new workflow (Moderation) apply it to the previously created content type (Foo).

Steps to reproduce:

  1. Add a new content for the Bar content type do not add a paragraph yet
  2. Add a new content for the Foo content type and load the existing Bar entity into the Inline form field
  3. Save the entity
  4. Go back to the Foo entity's edit page and open the Inline form field's referenced Bar entity with the Edit button
  5. Click on the Add new paragraph button in the Paragraph field named field
  6. Nothing should happen which is the sign that the problem exists
  7. Check the Network tab in the Browser's developer tool and you will see the Internal Server error message.

Expected behavior

The expected behavior is that the Add new paragraph button adds the paragraph fields to the form.

Proposed solution

I've created a patch, where the EntityTypeInfo.php's entityPrepareForm method is "fixed".
The problem was that the $entity and the $form_object->getEntity() objects were not the same in case when I used the Inline Entity Form.
And the method only checked if the $form_object is moderated entity form or not, but didn't check if the $entity itself is a moderated entity or not. I also added the $form_object->getEntity() === $entity so this way only the correct entity will get the new revision.

That is the point where I'm uncertain about that the problem lays here at the Content moderation module or in the Inline Entity Form, because the $entity comes from the latter one. I think the content moderation module should check if the received $entity is moderated and belongs to the current form object or not. This way the default behavior persists and the Inline Entity Form incompatibility is fixed, because the module won't try to create a new revision for the wrong entity and won't overwrite the entity in the $form_object.

Comments

Kova101 created an issue. See original summary.

Kova101’s picture

sam152’s picture

Status: Active » Postponed (maintainer needs more info)
Issue tags: -content moderation, -inline entity form

Re: tags.

You haven't really described in the steps to reproduce where content moderation is involved. Are you saying if some content type Foo has an IEF to some content type Bar, which has a content moderation workflow applied, there is an error?

I think without the proper concept of nested entity forms in core, this will be quite difficult to test with core itself.

Re: the patch

+++ b/core/modules/content_moderation/src/EntityTypeInfo.php
@@ -285,7 +285,12 @@ public function entityPrepareForm(EntityInterface $entity, $operation, FormState
+      && $this->moderationInfo->isModeratedEntity($entity)

Isn't this already checked in isModeratedEntityEditForm?

Kova101’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Needs work

Hello Sam152,

Thank you for the answer. I've updated the description to contain more detailed steps.
You are right the isModeratedEntityEditForm method checks isModeratedEntity.

The main problem we faced during a project is that a Foo entity has content moderation applied for it and also has a IEF that points to a Bar entity that has Paragraph fields and the Add new or Remove functions do not work within the IEF.

I've been able to fix the problem in the EntityTypeInfo's entityPrepareForm method with the attached solution. The problem I've found is that the IEF calls the hook_entity_prepare_form and the $entity that passed to it is the entity that is in the IEF so the Bar entity, but the $form_state is for the whole form, so basically for the Foo entity. And the EntityTypeInfo's entityPrepareForm sees that the Foo entity is moderated and creates a new revision for it from the $entity which in this case "incorrectly" is the Bar entity.

This results in overriding the form object's enity from Foo to Bar, which ends up causing errors because of different fields.

I had a lot of trouble to decide where to put this issue, because I think it should be in the IEF module, but I could not resolve the problem at that level, because manipulating the $form_state there is not a good practice in my opinion. So I've decided to put it here with a basic patch, hoping someone could help me with this situation.

I hope it is more understandable now. If you have questions then please do not hesitate to ask it. Or if you have some advice or solution I would appreciate it.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

ershov.andrey’s picture

StatusFileSize
new1.01 KB

Patch updated for Drupal 8.8.1 version

geek-merlin’s picture

IEF Comaintainer here. @Kova101 #5: Thanks a lot for your clarifiations!

>The problem I've found is that the IEF calls the hook_entity_prepare_form and the $entity that passed to it is the entity that is in the IEF so the Bar entity, but the $form_state is for the whole form, so basically for the Foo entity.

Are you sure? Can you provide a backtrace for this? Background: I stumbled upon this when i realized that neither IEF nor paragraphs currently invoke that hook, and validated via grep.

(EDIT: Do you mean hook_entity_prepare_form or EntityTypeInfo::entityPrepareForm that is mentioned in the IS?)

Another thing, whatever you see passing not-matching form state, the answer is likely to be SubformState.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.