The "Remove" button should be removed from forms if "Required field" is true and the "Allowed number of values" field of the Entity Reference Revision (or some of fields of the referenced entity) is configured as "Limited" to 1... It does make sense to display this button if the paragraph type should always exists.

Also, it should be interesting to have an option in the of the "Manage form display" to always hide control buttons.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

@baux created an issue. See original summary.

@baux’s picture

Issue summary: View changes
miro_dietiker’s picture

Status: Active » Postponed (maintainer needs more info)

It does. If you have multiple allowed paragraph types with cardinality 1, we may add a default paragraph while you still can remove it and add a different one.

If the allowed types are limited to 1 though, we should remove the button. But i was pretty sure we already hide it in that case.

Plz chk and provide feedback.

@baux’s picture

Hi Miro,

you are right. I was not thinking about more than one allowed types, but if I have just one (which is my case), the system display the Remove button... It´s not an important issue, but it should be hided. Thanks

miro_dietiker’s picture

Title: Remove "Remove Button" option from forms » Hide "Remove" button if cardinality 1 (required) and only one allowed Paragraph type
Status: Postponed (maintainer needs more info) » Active

OK then, yeah. Let's hide that button in this case.

Updating title to better identify the situation.

Daniel.Moberly’s picture

Attaching a patch for this. Should check for both conditions.

johnchque’s picture

Version: 8.x-1.0 » 8.x-1.x-dev
Issue tags: +Needs tests

We also need tests. :) And let's move this to dev. :)

santhosh.p’s picture

Assigned: Unassigned » santhosh.p
santhosh.p’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
68.74 KB

Patch #6 applied and tested successfully. After applying the patch #6 "Remove" button is removed from the form when "Required field" is true and the "Allowed number of values" is configured as "Limited" to 1.

santhosh.p’s picture

Assigned: santhosh.p » Unassigned
miro_dietiker’s picture

Status: Reviewed & tested by the community » Needs work

@santhosh.p Thank you for manually testing the patch. However, we do not accept RTBC patches without automated test coverage.Not all maintainers are that strict, but we are.

That's what @yongt9412 meant with "needs tests" and we always refer to.
See: https://www.drupal.org/issue-tags/special

The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

CRZDEV’s picture

Hi, i've checked patch #6 and seems not taking into account the required field configuration.
Remove button was not visible even with required field disabled.

Here goes a new patch with that fixed and adding some comments to explain the reason of the change.
Test are still pending so i'll keep the issue into needs work state. Please review.

miro_dietiker’s picture

Status: Needs work » Needs review

Still triggering the testbot once.

miro_dietiker’s picture

For the old widget (the code you touch) this would be a feature and it is feature frozen.

I was always talking of the new experimental widget.. (actually quite stable..) :-)

miro_dietiker’s picture

Status: Needs review » Needs work

Finally tested the new widget and yes, the Remove button really still shows with cardinality 1 and required.

So let's focus on that widget.

CRZDEV’s picture

Here goes a new version for experimental widget, also including test that may need some fixes.

Please review. Thanks!

Status: Needs review » Needs work

The last submitted patch, 16: hide_remove_cardinality_1_one_paragraph_type-2919186-16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

CRZDEV’s picture

Adding new version with some test fixes.

Status: Needs review » Needs work

The last submitted patch, 18: hide_remove_cardinality_1_one_paragraph_type-2919186-17.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

CRZDEV’s picture

CRZDEV’s picture

Status: Needs work » Needs review
Berdir’s picture

+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -2408,4 +2407,26 @@ class ParagraphsWidget extends WidgetBase {
+  protected function removeButtonAccess(ParagraphInterface $paragraphs_entity) {

I really don't like our usage of $paragraphs_entity. We don't do $node_entity either. Changing the existing variables is tricky as it would conflict, but lets not add new ones. Just $paragraph.

Status: Needs review » Needs work

The last submitted patch, 20: hide_remove_cardinality_1_one_paragraph_type-2919186-18.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

CRZDEV’s picture

Thanks for the reply Berdir, i used the variable name that is used in the whole paragraph widget file.
Maybe is a good idea to change it.

CRZDEV’s picture

Fixed some test exceptions

CRZDEV’s picture

@Berdir I completely agree with that, uploading new version with that variable name suggestion. Thanks!

johnchque’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests

Solid patch, thank you! :) Please remember to upload interdiff files every time you upload a new patch. :)

  • miro_dietiker committed 5b5532c on 8.x-1.x authored by CRZDEV
    Issue #2919186 by CRZDEV, Daniel.Moberly, santhosh.p, miro_dietiker:...
miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Rewrote the access method a bit. The code is longer, but the logic is flattened. I prefer trivial-to-read early access methods.

And committed, thx all for helping. :-)

johnchque’s picture

Status: Fixed » Needs review
FileSize
1.67 KB

When running tests I noticed something strange, this changes should make tests more reliable.

johnchque’s picture

[Duplicated]

miro_dietiker’s picture

Status: Needs review » Needs work

Before fixing "something strange" i like to hear what the problem was.

Likely needs a reroll anyway with the most recent commits.

johnchque’s picture

Status: Needs work » Needs review
FileSize
1.97 KB

Indeed, rebasing.
Sorry, I should have been more specific.
There were two problems in tests. First, we had two paragraphs types created but we were suppose to have only one so we can check that the remove button when field cardinality is 1, required and only one allowed paragraph type, is not present.
Second, since the fixed bug was not being triggered, cause there are two paragraphs types, we never really checked if the remove button was present or not. So I removed the second paragraph type created and added an assertion for the text field that it is supposed to be shown. :)

Berdir’s picture

Status: Needs review » Reviewed & tested by the community

Ah yes, makes sense.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Aaaand committed! :-)

CRZDEV’s picture

Thanks all guys and great work :)

Status: Fixed » Closed (fixed)

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

JasmineWu’s picture

I try to hide 'Remove' button of paragraphs when field is required, and i patched #12 but failed. So i create a patch for V1.11

JasmineWu’s picture

FileSize
1.23 KB
JasmineWu’s picture

FileSize
1.14 KB
codechefmarc’s picture

We also ran into this issue and the original fix didn't seem to make it work for us, but I added JasmineWu's patch #41 and that worked perfectly. I wonder if we need to open a new issue to get this patch included in a future release?

Berdir’s picture

That patch is changing the old legacy widget. If you want to use newer features, you need to use the new widget which has tons of improvements.

codechefmarc’s picture

Got it. We aren't using the Paragraphs widgets, we're using Layout Paragraphs widgets, so this patch will work for us for now. Thanks!