Spawn paragraphs in collapsed state

Created on 25 February 2021, about 4 years ago
Updated 23 May 2025, about 9 hours ago

Problem/Motivation

User story...

As a content editor using paragraphs_sets to add a lot of complex paragraph content, I want paragraphs to spawn collapsed, so my entity form is less overwhelming.

Currently, paragraphs_sets spawns paragraphs in an "open" state ("edit mode") i.e.: similar to the default behaviour when you click the "Add more" button on the paragraphs field.

Once a paragraph has been added to a page, it is possible to "Close" / "Collapse" it to just a summary. This is easier to read and takes up less vertical space.

The site I'm working on is using paragraphs_sets to spawn lengthly, pre-defined lists, i.e.: where each paragraph is an item in the list, and there are often 7 or more items in a list. Each of the list items has a title field, which paragraphs_sets populates, and a bunch of optional additional data that will be filled in later on, resulting in loooooong node/add pages, meaning the content editor has to do a lot of unnecessary scrolling to get to the rest of the node/add form.

Contrast this with when the content editor goes to edit the node later on: we can configure the widget to collapse / close the paragraphs on the node/edit page, and the client prefers this interface.

Ideally, paragraphs_sets could spawn the paragraphs in a collapsed state, reducing the work / information overload on the content editor, while still allowing them to customize the paragraphs they want (i.e.: by expanding / opening / clicking "edit" on them) similar to what they do on the node/edit form.

Proposed resolution

Provide a way for paragraphs_sets to spawn paragraphs in a collapsed state.

Not sure exactly how: ideally, paragraphs spawn collapsed; but if that's not possible, we might have to collapse paragraphs after they've spawned.

Remaining tasks

  1. Review and feedback
  2. RTBC and feedback
  3. Commit
  4. Release

User interface changes

  1. Add a "Default state for new paragraphs" select list to the ParagraphsSetForm, i.e.: at /admin/structure/paragraphs_set/add and /admin/structure/paragraphs_set/{paragraphs_set}

API changes

  1. Added a public \Drupal\paragraphs_sets\Entity\ParagraphsSet::$new_paragraph_mode field
  2. Added a public \Drupal\paragraphs_sets\ParagraphsSetInterface::getNewParagraphMode() function
  3. Added a \Drupal\paragraphs_sets\ParagraphsSetInterface::PARAGRAPH_MODE_CLOSED constant
  4. Added a \Drupal\paragraphs_sets\ParagraphsSetInterface::PARAGRAPH_MODE_OPEN constant

Data model changes

  1. Added a new_paragraph_mode field to the paragraphs_sets.set.* configuration schema; i.e.: to the set of config_export data for the paragraphs_set configuration entity.
🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

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

Merge Requests

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.71.5 2024