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.
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | restore_paragraphs_collapse_and_drag_drop_functionality-3205212-007.patch | 1.1 KB | stefan.korn |
| #3 | 3205212-3.patch | 3.32 KB | brittany.huntzberry |
Comments
Comment #2
brittany.huntzberryAlso 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.
Comment #3
brittany.huntzberryAlright, 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...
Comment #4
devkinetic commentedI 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.
Comment #5
devkinetic commentedComment #6
vaibhavjainThe patch works well for me.
However, as suggested, it may need a rewrite.
Comment #7
stefan.kornpatch 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.
Comment #8
stefan.kornComment #9
parisekThis is still issue, patched worked for me
Comment #10
devkinetic commentedThanks for the report. I've reviewed the patch and all looks well. marking as RTBC, and slated for merge.
Comment #11
devkinetic commentedComment #13
smustgrave commented