The experimental widget drop-down shows "Duplicate" even when the field storage setting is 1. The paragraph then can be duplicated but the page cannot be saved (Message: MyField: this field cannot hold more than 1 values). For this use case “Duplicate" should not be available in the drop-down.

Comments

Thomas Factory created an issue. See original summary.

johnchque’s picture

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

Nice catch. Let's try to get some failing tests here then. :)
Let's go to dev. :)

miro_dietiker’s picture

Also just stumbled across this.

We fixed something similar for the remove button.
5b5532c #2919186: Hide "Remove" button if cardinality 1 (required) and only one allowed Paragraph type

johnchque’s picture

Assigned: Unassigned » johnchque

Working on this. :)

johnchque’s picture

Status: Active » Needs review
StatusFileSize
new1.33 KB
new2.77 KB

This should work. :)

berdir’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -2491,4 +2491,32 @@ class ParagraphsWidget extends WidgetBase {
+
+    // Hide the button if field cardinality is one.
+    if ($cardinality == 1) {
+      return FALSE;
+    }

A more generic way of putting this would be to say that duplicate should follow a similar rule as adding a new paragraph. It should not be allowed if there is a fixed cardinality. So e.g. if you have cardinality 2 and 2 paragraphs you shoudln't see it but you should if you only have one.

But I think that's very hard to check inside the item loop, when you have to consider deleted paragraphs and so on.

So I think this is fine, a fixed cardinality > 1 is a pretty rare use case I think.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed

Yeah, let's cover the basic case here. Committed and thanks! :-)

Ralf Eisler’s picture

Thank you very much for the patch, it works!

However, there is still markup left (td.field-multiple-drag.paragraph-bullet), when the field storage setting is 1 (which would’t be a problem, if the table cell collapsed).

Will you keep the the table-wrapper in the future for this use case (I do extensible backend-styling)?

berdir’s picture

Yes, we recently simplified to always show the table even when it is single value. Drag and drop changes are possible but likely then configurable.

Ralf Eisler’s picture

Great!

Status: Fixed » Closed (fixed)

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

idebr’s picture

#7

A more generic way of putting this would be to say that duplicate should follow a similar rule as adding a new paragraph. It should not be allowed if there is a fixed cardinality. So e.g. if you have cardinality 2 and 2 paragraphs you shoudln't see it but you should if you only have one.

I created a follow-up to fix this issue: #3115916: Do not show 'Duplicate' action when maximum items has been reached for fields with cardinality > 1