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
- Enable Require on Publish, Paragraphs, and Content Moderation.
- Create a Paragraph type with at least one field Required on Publish.
- Add the Paragraph type as a field to Basic Page.
- Add the Editorial workflow to Basic Page (
/admin/config/workflow/workflows/manage/editorial) - 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #46 | require_on_publish_fix-paragraphs-content-moderation-3178100-46.patch | 4.58 KB | jcandan |
Issue fork require_on_publish-3178100
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
Comment #2
alt.dev commentedHere 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.
Comment #3
alt.dev commentedWe 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:
Comment #4
alt.dev commentedWe 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.
Comment #5
lysenkoThe 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.
Comment #6
mpriscella commentedI 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.
Comment #7
boddy commentedI 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.
Comment #8
bohartPatch #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.
Comment #9
quadrexdevWe'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 -
I think this patch needs work to cover this case.
Comment #11
quadrexdevAttaching a patch that fix the issue above
Comment #12
andrerb commentedRe-roll patch
- Fix error for taxonomies
- update for D10 compatibility
Comment #13
andrerb commentedComment #14
andrerb commentedUpdate D10 compatibility from #13
- remove obsolete "core: 8.x" from .info.yml
Comment #16
steffenrI've updated the patch to work with latest 8.x-1.x-dev.
Unfortunately i cannot push to the existing Merge Request.
Comment #17
steffenrUpdated patch, cause i missed a duplicate line..
Comment #18
steffenrComment #19
steffenrFinally.. ;) Sorry for confusion in the last comment.
Comment #20
steffenrAnd 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. 💚
Comment #21
andrerb commentedRebased and updated the patch.
Comment #22
steffenrThe 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.
Comment #23
steffenrComment #26
stborchertSorry, 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
Comment #27
aaronmchaleThis 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?
Comment #28
aaronmchaleMy 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.
Comment #30
tejavardhanreddy commentedComment #31
stborchert@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.
Comment #32
markdorisonPlease 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.
Comment #36
jcandan commentedTitle 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#statescondition handling, that might address this issue.Update: See next comment.
Comment #37
jcandan commentedYa 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!
Comment #38
jcandan commentedOkay. There is quite a bit going on here.
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.
Comment #39
jcandan commentedOriginal 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
Proposed resolution
Comment #42
jcandan commentedComment #44
jcandan commentedComment #45
jcandan commentedReady for review.
Comment #46
jcandan commentedRolls fresh patch from MR !27.
Comment #47
jcandan commentedAm considering this for 2.0.0, or 2.0.1, depending on the speed with which we get a review.
Comment #48
jcandan commentedNeeds test coverage.
Comment #49
jcandan commentedAdded significant test coverage including Paragraphs and Content Moderation support. Needs review. Any takers?
Comment #50
jcandan commentedComment #53
jcandan commented