Restore Paragraphs' Collapse and Drag & Drop functionality

Created on 23 March 2021, over 3 years ago
Updated 5 April 2024, 3 months ago

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.

✨ Feature request
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada matt.macintyre

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024