Problem/Motivation
There seem to be many issues around drag-and-drop and some others may be related or need to be resolved before a final fix can be implemented for this one in particular.
When a field has a cardinality of 1, it still gets displayed in a draggable table via field_multiple_value_form. This has been discussed in the very old issue
#2272221 →
already, but not quite properly fixed in the current version for D8+. It may have been fixed for a while and perhaps a change to Drupal core broke it again. The paragraphs_preprocess_field_multiple_value_form() function sort of addresses it by trying to remove the table columns that shouldn't be displayed if the cardinality is 1, but it's no longer removing the right table columns. With the latest version of D10 (possibly earlier, can't go back and test/verify at this point), column 2 in the header and 3 of the rows needs to be removed for this to work properly.
Furthermore, it still displays the header actions button with a "Drag & drop" option to select, which shouldn't be there for a cardinality of 1.
Steps to reproduce
- Use the latest version of Paragraphs in Drupal 10.2.3
- Create a paragraphs field on a node (or other entity) with a cardinality of 1
- Create/edit that entity and see it still shows the "Order" header and there's a gap to the right of the paragraph item under the "Order" column heading
Proposed resolution
One solution is to update the paragraphs_preprocess_field_multiple_value_form() function to remove the correct columns from the table header and each of the rows. However, that seems fragile, as it would have to be updated again if there's another change to multiple value tables in core at some point in future.
Instead, my suggestion is to go into the formMultipleElements function of the ParagraphsWidget class and around line 1397 where it sets the #theme to field_multiple_value_form, fix the cardinality options as follows:
REMOVE the '#cardinality' key since it's already set a few lines above, then set the '#cardinality_multiple' key like this:
'#cardinality_multiple' => ($cardinality > 1)
This simply won't render the table.
Then the header actions need to be updated to not show a drag and drop option based on cardinality, but I couldn't see where to fix that. As a short term solution, I created my own field widget plugin that extends the ParagraphsWidget class. It overrides formMultipleElements to first call the parent method and then alter the #cardinality_multiple key based on actual cardinality. I then had the buildHeaderActions method overridden to return an empty array, since in my case I'm only ever going to use my field widget for paragraph fields with a cardinality of 1 anyway.