Problem/Motivation

With autocollapsing, we have a nice minimal UI.

This might be unsatisfying for a deep nested situation with containers.

Proposed resolution

Allow option to collapse only regular content items and keep the containers open.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

miro_dietiker created an issue. See original summary.

miro_dietiker’s picture

Priority: Normal » Major
Issue tags: +Usability

This seems like an important UX step.

miro_dietiker’s picture

UX wise, i want to look into this idea.

One idea is that we offer a setting where collapsing always only affects the regular form fields, while the full hierarchy is always output. Thus hierarchy expand/collapse would be a non-ajax operation.

We need to assess how much slow down this causes for reference situations.

This already needs a certain level of client side summary update.

miro_dietiker’s picture

This came up again because by adding containers combined with collapsed display editors loose overview.

Actually our use case would be to expand top level containers only. This can be achieved if it is a widget setting.

arpad.rozsa’s picture

StatusFileSize
new7.76 KB

I added the new edit mode "Closed, expand nested" to the widget settings and a test to check, if only the top level container is opened, when using this new mode.

miro_dietiker’s picture

This looks very nice. :-)

berdir’s picture

+++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
@@ -384,6 +385,17 @@ class ParagraphsWidget extends WidgetBase {
 
+    if ($default_edit_mode == 'closed_expand_nested' && $form_state->getTriggeringElement() === NULL) {
+      $field_definitions = $paragraphs_entity->getFieldDefinitions();
+
+      foreach ($field_definitions as $field_definition) {
+        if ($field_definition->getType() == 'entity_reference_revisions' && $field_definition->getSetting('target_type') == 'paragraph') {
+          $item_mode = 'edit';
+          break;
+        }
+      }
+    }

So this relies on overwriting the default if this is no submission by relying on the trigger element. Interesting approach.

Wondering if it would be easier to follow if you'd instead embed it into the logic above, something like this:

elseif (closed) {
closed
}
elseif (closed_expand_nested) {
default to closed then the code you have.

Other than that, this looks great, even has test coverage for nested containers to ensure that if you do want to have nested expanded too, you can do that with the widget settings there.

berdir’s picture

Status: Active » Needs work
arpad.rozsa’s picture

Status: Needs work » Needs review
StatusFileSize
new7.45 KB

It is easier and I wanted to do it like you described, but first getting the field definitions in that elseif, didn't want to work exactly how it should've, so I went with the solution I uploaded before, But after rechecking everything now, it works fine, so I updated the code.

berdir’s picture

Title: Allow option to not autocollapse containers » Add edit mode option to expand only paragraph types with paragraph field

For next time: When updating a patch, you should provide an interdiff, so that it is easier to review the changes you did. See https://www.drupal.org/documentation/git/interdiff. I usually just do that by working on a branch, and committing each version, then the interdiff is just git diff HEAD~1.

Trying to set a better title, this has nothing to do with the autocollapse feature, only the regular edit mode.

And the current label for the option is also not confusing, I suggested that and I'm not sure what else to use. We don't expand nested paragraphs, we expand paragraphs that *have* nested paragraphs :)

Miro?

miro_dietiker’s picture

Hm, you removed the term "container" from the title - i would consider "Closed, expand containers" appropriate, but i see that this is maybe an unknown term.

In fact we are not only expanding the ones with children, but also empty ones that could have children.
I also thought about using generic tree terms (leave, node) but there's too much clashing with Drupal nodes.
So no good idea yet.

miro_dietiker’s picture

Status: Needs review » Fixed

Closed, expand nested => Closed, show nested

Committed otherwise as is.

Status: Fixed » Closed (fixed)

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