Problem/Motivation

This bug renders the require on publish feature unusable with no workaround when used on a Paragraph field that is part of a content entity with Content Moderation.

Steps to reproduce

  1. Enable Require on Publish, Paragraphs, and Content Moderation.
  2. Create a Paragraph type with at least one field Required on Publish.
  3. Add the Paragraph type as a field to Basic Page.
  4. Add the Editorial workflow to Basic Page (/admin/config/workflow/workflows/manage/editorial)
  5. Create a Basic Page content.

When the node you create is published and the required on publish Paragraph sub-field is empty, the node is published and the "required when publish" message is not shown.

Proposed resolution

Conditionally check is published against status and against Content Moderation when appropriate.

See b027454 for inspiration.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

alt.local created an issue. See original summary.

alt.dev’s picture

Status: Active » Needs review
StatusFileSize
new6.56 KB

Here is a patch that adds logic to extract the 'Published' value from the POST data.

The patch was created in contributing with @bohart so it would be great if he will get a credit as well.

alt.dev’s picture

StatusFileSize
new6.49 KB

We faced an issue with our previous approach. If we enable the content moderation module it will hide the preview field which means that isPublished() value will always be FALSE for paragraph and therefore they won't validate.

Me with @bohart created new patch which skips the validation for paragraph entities and then vildatates all entities paragraph entities when the ConstraintValidation is called from the parent entity.

The only problem, for now, is that we should put a proper path when we build a violation for paragraphs.
I have tried to add atPath($field->getName() . ".{$delta}.subform." . $violation->getPropertyPath()) but in this case, EXPERIMENTAL paragraph widget won't expand if it contain empty required field.

TODO:

  • Pass a proper path to the atPath() method that is called from paragraph's section.
alt.dev’s picture

StatusFileSize
new9.18 KB

We got another idea on how to resolve the issue. We decided to extract the published state based on the moderation_state value in the POST data.

lysenko’s picture

StatusFileSize
new9.22 KB

The patch has been updated to have compatibility with a new release module.

The patch was created in contributing with @bohart so it would be great if he will get a credit as well.

mpriscella’s picture

I believe I may have inadvertently fixed this issue while cleaning up some logic in https://www.drupal.org/project/require_on_publish/issues/3205913. Can anyone who uses this patch verify? In either case, I'll make sure credit is attributed to everyone who worked on the patches here since a lot of the ideas overlap.

boddy’s picture

I had verified the new release, unfortunately children paragraphs have 0 in the $is_published and as result their fields with 'required on publish' does not checked at all.
So the patch has been updated to have compatibility with a new release module.
I do not provide an interdiff.txt because the patch was rerolled.

bohart’s picture

Title: Paragraphs can't get parent entity. » content_moderation support
Version: 8.x-1.3 » 8.x-1.6
Status: Needs review » Reviewed & tested by the community

Patch #7 has been applied to one of our projects and it works great.
Tested on: Drupal 9.1.7 + Require On Publish 1.6

Hope to see it committed to one of up next releases!
Thanks.

quadrexdev’s picture

Status: Reviewed & tested by the community » Needs work

We're using this patch on a project as well. Everything works well except for a case when the paragraph is added inside the TaxonomyTerm entity.

It throws the following error -

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "taxonomy" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 143 of core/lib/Drupal/Core/Entity/EntityTypeManager.php).

I think this patch needs work to cover this case.

quadrexdev’s picture

StatusFileSize
new6.42 KB

Attaching a patch that fix the issue above

andrerb’s picture

StatusFileSize
new6.62 KB

Re-roll patch
- Fix error for taxonomies
- update for D10 compatibility

andrerb’s picture

StatusFileSize
new7.48 KB
andrerb’s picture

StatusFileSize
new7.49 KB

Update D10 compatibility from #13
- remove obsolete "core: 8.x" from .info.yml

steffenr’s picture

StatusFileSize
new7.47 KB

I've updated the patch to work with latest 8.x-1.x-dev.

Unfortunately i cannot push to the existing Merge Request.

steffenr’s picture

StatusFileSize
new7.43 KB

Updated patch, cause i missed a duplicate line..

steffenr’s picture

steffenr’s picture

StatusFileSize
new7.43 KB

Finally.. ;) Sorry for confusion in the last comment.

steffenr’s picture

Version: 8.x-1.6 » 8.x-1.x-dev
StatusFileSize
new7.55 KB

And another reroll, because the method entityIsPublishable was not working correctly, because the name of the module was passed to getDefinition instead of the bundle name.

@AndreRB: It would be great, if you could update the MR with the latest patch. 💚

andrerb’s picture

Rebased and updated the patch.

steffenr’s picture

StatusFileSize
new7.98 KB

The patch still had problems while translating entities, because the route object did not contain the _entity_form key.
I added an additional check for filled $form_arg and a logic to get the entity_type_id from the route object.

steffenr’s picture

Status: Needs work » Needs review

stBorchert made their first commit to this issue’s fork.

stborchert’s picture

Sorry, I f*d up MR5. Created a new branch: https://git.drupalcode.org/project/require_on_publish/-/merge_requests/15

Credits go to @AndreRB and @SteffenR

aaronmchale’s picture

This doesn't seem to work for paragraphs which have been added to storage entities, where storage entities are embedded using inline_entity_form. For that matter, it also doesn't work for any field added in a storage entity.

Maybe there's a way to make this work for more than just paragraph entities, like any entity which is embedded within the parent entity using inline_entity_form?

aaronmchale’s picture

My previous comment may not apply actually., I had not set the entity reference field itself to require on publish, after doing that things seem to be working better, but I need to do some testing tomorrow.

TejaVardhanReddy made their first commit to this issue’s fork.

tejavardhanreddy’s picture

Version: 8.x-1.x-dev » 8.x-1.10
StatusFileSize
new7.59 KB
stborchert’s picture

Version: 8.x-1.10 » 8.x-1.x-dev

@TejaVardhanReddy Patches are always created to the development branch, not existing releases. 8.x-1.0 is already released and cannot be changed anymore.
Additionally, when providing a patch, please add an interdiff, so reviewers can see what has changed since the last patch.

markdorison’s picture

Please ensure that the lastest changes are included in a merge request so that tests can be run. Tests are no longer run on patches since we have switched to GitLabCI.

steffenr changed the visibility of the branch 3178100-content-moderation-support to hidden.

steffenr changed the visibility of the branch 3178100-paragraphs-cant-get to hidden.

steffenr changed the visibility of the branch 3178100-paragraph-validation to hidden.

jcandan’s picture

Title scope seems to duplicate #3005936: Required on Workflow State, however a cursory review of the issue summary and discussion lead me to think not so.

Either way, I do wonder if there's any chance #3530547: Add require on publish #states Form API handling fixes this. I haven't tested, but since it adopts #states condition handling, that might address this issue.

Update: See next comment.

jcandan’s picture

Ya know! Actually, I missed this ticket when I created #3530652: Fix Paragraphs support with Content Moderation. Please take a moment to review the patch/MR there. Sorry for the duplicate effort!

jcandan’s picture

Okay. There is quite a bit going on here.

  1. The original issue summary steps to reproduce make no mention of content moderation.
  2. It turns out that he did fix the original issue as stated in #6.
  3. Others jumped in and suggested it was content moderation where it failed, which is true after #6 was merged.
  4. From thence, many have put forward several independent efforts to address this issue.
  5. Including my own duplicate issue noted above.

I will mark my issue as a duplicate, as well as #3373969: Paragraphs integration not working with core workflows/content moderation.
I will port my work from #3530652: Fix Paragraphs support with Content Moderation so I can give folks here credit for their contributions.

Once I get that ported over to a new MR associated with a fork here, please conduct reviews to ensure this addresses the issue well.

jcandan’s picture

Title: content_moderation support » Fix Paragraphs support with Content Moderation
Priority: Critical » Major
Issue summary: View changes

Original summary

Problem

The logic that has been added to the RequireOnPublishValidator for the paragraph entities is not correct. Paragraph can't get the parent entity since it doesn't exist when a user creates a new node. Also, even on the node edit, when a node exists and the paragraph can extract the parent entity, it will get the original node rather than a new one and therefore it will contain the old 'Published' value.

Steps to reproduce
  • Create a paragraph type with the 'Require on publish' option enabled.
  • Add this paragraph to a node.
  • Create a new entity with an unchecked 'Publish' option.
  • Observe that 'Require on publish' validator returns an error for the required paragraph fields.

Proposed resolution

  1. Since at the moment, when a user submits the form validation constraint doesn't have the fresh node, we need or extract the published value from the POST data
  2. Skip the validation for the paragraph entities and when constraint function goes through all entity fields, find paragraphs fields, get paragraph entity and then go through all paragraph fields as well.

jcandan changed the visibility of the branch 8.x-1.x to hidden.

jcandan changed the visibility of the branch 3178100--content-moderation to hidden.

jcandan’s picture

jcandan’s picture

Status: Needs review » Needs work
jcandan’s picture

Status: Needs work » Needs review
Issue tags: +content moderation

Ready for review.

jcandan’s picture

Rolls fresh patch from MR !27.

jcandan’s picture

Version: 8.x-1.x-dev » 2.0.0-rc1

Am considering this for 2.0.0, or 2.0.1, depending on the speed with which we get a review.

jcandan’s picture

Status: Needs review » Needs work

Needs test coverage.

jcandan’s picture

Status: Needs work » Needs review

Added significant test coverage including Paragraphs and Content Moderation support. Needs review. Any takers?

jcandan’s picture

Version: 2.0.0-rc1 » 2.0.x-dev

  • jcandan committed 7a0a2d6d on 2.0.x
    Issue #3178100 by alt.dev, lysenko: Fix Paragraphs support with Content...

  • jcandan committed 7a0a2d6d on 2.1.x
    Issue #3178100 by alt.dev, lysenko: Fix Paragraphs support with Content...
jcandan’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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