Problem/Motivation

When enabled, the Field Config Cardinality module removes the "Collapse All / Drag & Drop / Edit All" dropdown provided by the Paragraphs Experimental Widget.

Steps to reproduce

Create a paragraph, add an entity reference revisions field to another paragraph type, and set the form display to Paragraphs Experimental widget. There should be 3 dots in the top right of the widget. When Field Config Cardinality is enabled, these dots are missing.

Proposed resolution

On line 152 of the module file, the module implements HOOK_preprocess_field_multiple_value_form().

I'm probably missing something, but in my testing, removing everything inside this function after line 183 (not including that line) fixes the issue, but still allows the cardinality to be set and respected at the instance level.

So, the entire content of that function would be:

function field_config_cardinality_preprocess_field_multiple_value_form(&$variables) {
  $element = $variables['element'];

  $variables['multiple'] = FALSE;
  if (!empty($element['#cardinality_multiple'])) {
    $variables['multiple'] = $element['#cardinality_multiple'];
  }
  else if (!empty($element['#multiple'])) {
    $variables['multiple'] = $element['#multiple'];
  }

  if ($variables['multiple'] == TRUE && isset($element['#attributes']['data-fcc'])) {
    $cardinality_config = $element['#attributes']['data-fcc'];

    if (!empty($cardinality_config)) {
      $order_class = $element['#field_name'] . '-delta-order';

      $rows = [];

      // Sort items according to '_weight' (needed when the form comes back after
      // preview or failed validation).
      $items = [];
      $variables['button'] = [];
      foreach (Element::children($element) as $key) {
        if (is_integer($key)) {
          $items[] = &$element[$key];
        }
      }

      if (count($items) <= $cardinality_config - 1 || $cardinality_config == '-1') {
        $variables['button'] = &$element['add_more'];
      }

      usort($items, '_field_multiple_value_form_sort_helper');
    }
  }
}

Remaining tasks

Testing.

User interface changes

None.

API changes

None.

Data model changes

None.

Comments

matt.macintyre created an issue. See original summary.

brittany.huntzberry’s picture

Also experiencing this issue. I noticed that the Paragraphs EXPERIMENTAL widget settings also introduce a problem when enabling Duplicate setting-- it allows the paragraphs to be duplicated even with a limited Cardinality set with this module.

I'm thinking it could be good to reference some logic from Paragraphs Sets to get the header buttons to work. See: https://git.drupalcode.org/project/paragraphs_sets/-/blob/8.x-2.x/paragr...

However, there most likely needs to be some additional functionality for disabling Duplicate button on paragraphs when they're reached the Cardinality limit, just like how the Add more button is disabled. I'm going to see if I can get a patch / branch up for this over the weekend.

brittany.huntzberry’s picture

Status: Active » Needs review
StatusFileSize
new3.32 KB

Alright, here's a patch that should display the Collapse All / Edit All, and other Paragraphs actions. However, there's still the issue around the Duplicate action from Drop-down actions on Paragraphs. That will need extra work and may be hard to do without assuming Paragraphs is being used with this module as well...

devkinetic’s picture

I think the crux of this is that currently the module overwrites the table with a new one. I think a better solution would be to modify the existing rows in-place so we don't need to recreate all of the functionality. This would also allow it to play nice with any other module the deals with a table's sort/drag functionality.

devkinetic’s picture

Status: Needs review » Needs work
vaibhavjain’s picture

The patch works well for me.
However, as suggested, it may need a rewrite.

stefan.korn’s picture

patch from #3 is duplicating a lot of code from template_preprocess_field_multiple_value_form() from theme.inc

I think this is not necessary just to recover the paragraphs header functionality.

Providing a patch that just preserves the part relevant for paragraphs functionality.

Still it has to be considered that Claro theme (and Gin theme which is using Claro as parent) breaks the paragraphs functionality as well, see #3099024: Paragraphs actions button are removed when Claro admin theme is used and #3099026: Claro's preprocessing of field multiple value form's table header cell removes potential changes by others. If you use Claro or Gin you will need to fix this too.

Remark from devkinetic about refactoring field_config_cardinality_preprocess_field_multiple_value_form() might still be a good idea, but I did not consider this for the moment.

stefan.korn’s picture

Status: Needs work » Needs review
parisek’s picture

This is still issue, patched worked for me

devkinetic’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for the report. I've reviewed the patch and all looks well. marking as RTBC, and slated for merge.

devkinetic’s picture

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

  • smustgrave committed cede0353 on 4.0.x
    Issue #3205212 by stefan.korn, brittany.huntzberry, devkinetic, matt....
smustgrave’s picture

Version: 8.x-1.x-dev » 4.0.x-dev
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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