Problem/Motivation

#2943956: Experimental widget drop-down shows "Duplicate" even when the field storage setting is set to 1 implemented restrictions for when the 'Duplicate' action should be shown in the Paragraphs widget. However, these restrictions do not work for paragraphs with a fixed cardinality allowing more than 1 item.

Proposed resolution

Extend the 'Duplicate' action restrictions so it never shows when the maximum items has been reached.

Remaining tasks

  1. Write a patch
  2. Review
  3. Commit

User interface changes

The 'Duplicate' action never shows when the maximum items has been reached.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

idebr created an issue. See original summary.

idebr’s picture

Attached patch:

  • extends the access check for the 'Duplicate' button for the case the field cardinality has been reached.
  • adds test coverage for the access check.

The last submitted patch, 2: 3115916-2-test-only.patch, failed testing. View results

Danny Englander’s picture

FileSize
308.16 KB

I tested this patch in the following manner:

  • Installed Paragraphs via composer
  • Enabled paragraphs
  • Added a test paragraphs type and set the limit to a total of 3.
  • Added 3 paragraphs to my node and confirmed, I still saw the duplicate button. (Note adding beyond the limit will result in an error on node save.
  • Added the patch to composer:
    "patches": {
          "drupal/paragraphs": {
            "Do not show 'Duplicate' action when maximum items has been reached for fields with cardinality > 1": "https://www.drupal.org/files/issues/2020-02-25/3115916-2.patch"
          }
        }
  • Installed the patch via composer
  • I went back to the node in question and now, when I have reached the limit of 3, I do not see the duplicate button anymore.

Paragraphs screen capture after patching

Danny Englander’s picture

Status: Needs review » Reviewed & tested by the community
Berdir’s picture

Status: Reviewed & tested by the community » Fixed

Nice work with the fix, automated and manual tests, that's how it should be :)

  • Berdir committed 45c9794 on 8.x-1.x authored by idebr
    Issue #3115916 by idebr, Danny Englander: Do not show 'Duplicate' action...

Status: Fixed » Closed (fixed)

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