Problem/Motivation

The collapsed summary now only shows a summary of the first child of a container.
That's a good start, but it is misleading as it looks like there is only one child.

Related discussion:
For instance the drag and drop mode shows a summary AND also always shows the childrens below, indented. Repeating the children on the parent would lead do weird duplication. Also "container only" are likely to have plugins enabled and thus if no content fields, the summary would simply tell styles or grid settings chosen. And if none, then an empty summary is perfectly what i expect.

Proposed resolution

Either combine multiple children or at least display a child count.

If the closed mode will only hide the child content fields, but display child paragraphs fields, the situation would be different.
But in that case, child paragraphs fields would be excluded completely from the closed summary.

Since we are not sure what of these two options are the long term goal, we should implement both. Either use a setting or define a second closed mode. Add a new argument to Summary method, if ERR children should be part of the summary or not.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#47 consider_container-2852001-47.patch12.59 KBGinovski
#47 interdiff-2852001-45-47.txt1001 bytesGinovski
#45 consider_container-2852001-45.patch12.84 KBGinovski
#45 interdiff-2852001-43-45.txt1.16 KBGinovski
#43 consider_container-2852001-43.patch12.78 KBGinovski
#43 interdiff-2852001-41-43.txt1.36 KBGinovski
#41 consider_container-2852001-41.patch12.79 KBGinovski
#41 interdiff-2852001-39-41.txt9.82 KBGinovski
#39 consider_container-2852001-39.patch12.64 KBGinovski
#39 interdiff-2852001-37-39.txt9.7 KBGinovski
#37 consider_container-2852001-37.patch7.58 KBGinovski
#37 interdiff-2852001-34-37.txt1.27 KBGinovski
#34 interdiff-2852001-30-32.txt1.81 KBGinovski
#34 consider_container-2852001-32.patch7.26 KBGinovski
#30 consider_container-2852001-30.patch7.83 KBGinovski
#30 interdiff-2852001-28-30.txt1.88 KBGinovski
#28 consider_container-2852001-28.patch7.82 KBGinovski
#28 interdiff-2852001-26-28.txt1.35 KBGinovski
#26 summary-multivalue.png15.99 KBGinovski
#26 consider_container-2852001-26.patch7.82 KBGinovski
#26 interdiff-2852001-19-26.txt5.93 KBGinovski
#19 consider_container-2852001-19.patch7.69 KBthenchev
#19 interdiff-2852001-19.txt6.37 KBthenchev
#18 interdiff-2852001-18.txt1.71 KBthenchev
#18 consider_container-2852001-18.patch4.83 KBthenchev
#17 closed.png33.71 KBthenchev
#16 closed.png33.71 KBthenchev
#16 consider_container-2852001-16.patch4.31 KBthenchev
#16 interdiff-2852001-16.txt5.42 KBthenchev
#13 interdiff-2852001-13.txt856 bytesthenchev
#13 consider_container-2852001-13.patch4.59 KBthenchev
#11 interdiff-2852001-11.txt1.24 KBthenchev
#11 consider_container-2852001-11.patch3.76 KBthenchev
#9 consider_multivalue-2852001-9.patch3.72 KBthenchev
#9 nested_inside_nested.png14.91 KBthenchev
#9 nested.png17.92 KBthenchev
#6 closed.png29.41 KBthenchev
#6 open.png196.71 KBthenchev
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

miro_dietiker created an issue. See original summary.

thenchev’s picture

Assigned: Unassigned » thenchev
miro_dietiker’s picture

Status: Active » Postponed
Related issues: +#2857112: Add summary method into paragraph entity

So this is postponed on the move i guess.

Ginovski’s picture

Issue summary: View changes
Status: Postponed » Active

Returning to active since #2857112: Add summary method into paragraph entity is committed

Ginovski’s picture

Issue summary: View changes
thenchev’s picture

FileSize
196.71 KB
29.41 KB

If I understand correctly then the problem is with the nested paragraph so i updated it to display all referenced paragraphs. Also updated the getTextSummary() in Paragraphs to handle multivalue text field. Is this something we also want?

Primsi’s picture

Yes, the problem is with nested paragraphs. In Paragraph.php we have a summary method that recursively generates a summary. The challenge is how to make this nice from UX perspective.

If I understood it right, @miro_dietiker suggests two possible solutions:

  1. Display a child count if we have nested paragraphs
  2. Display information about what this nested paragraphs are

Both should be implemented for now and which one is used should be configurable on the widget config.

miro_dietiker’s picture

I don't want added configurability now. But i want a text representing the count, possibly first:
Example "5 Children". And then the summary of each.

We will use either by passing in additional arguments to functions. If we show the children in the summary depends if the child is separately displayed or not. This depends and might change with open / closed / drag & drop modes and more.

thenchev’s picture

Status: Active » Needs review
FileSize
17.92 KB
14.91 KB
3.72 KB

Here is the initial patch and some thoughts.

1. Removed the configurability but i can add it to widget settings if we decide.

2. In the first iteration my summary was like "1 Text paragraph, 2 Image paragraphs, 1 Container". It grouped the paragraph types and used that as a summary.

3. I don't know what the plan for further development but are we considering to use maybe image representations for paragraph types. So the summary for the container paragraphs could be: "1 [text paragraph image], 2 [image paragraph image], 1 [container image]" and hovering on the images we can show summary of the individual paragraphs?

4. Here are some images of how containers look:
Here is the top container:

This is the container inside the top container:

How do we want to display summary for the container inside the container? Separate with [] or some indicator that is a summary of a container inside.

Status: Needs review » Needs work

The last submitted patch, 9: consider_multivalue-2852001-9.patch, failed testing.

thenchev’s picture

This should fix some test fails.

Status: Needs review » Needs work

The last submitted patch, 11: consider_container-2852001-11.patch, failed testing.

thenchev’s picture

last fail

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Paragraph.php
@@ -474,6 +479,13 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
+    if ($nested == TRUE) {
+      return [
+        'count' => $count,
+        'summary' => strip_tags($collapsed_summary_text),
+      ];
+    }
     return strip_tags($collapsed_summary_text);

We can not vary the return type based on an argument. What we return should always be of the same type.

Unsure about outputting the paragraph types and sure also "Children". The thing is, the summary intentionally also skips field labels so the effective field values are getting visible. I think we should skip all these labels in the current design and think about outputting some when we have icons.

But in order to continue, we need all the follow-up issues created first before someone can commit this. I think even we need a new parent META that describes the general goal of how the summary should evolve and specific child issues that care about showing plugin icons, paragraph type icons for children with counters, ...

thenchev’s picture

Created meta issue for discussion #2862083: [META] Improve paragraphs summary. And continue to improve this...

thenchev’s picture

thenchev’s picture

FileSize
33.71 KB

sorry wrong image. this one is correct.

thenchev’s picture

Noticed that when the summary is closed by default the count is wrong so fixed that and will work on adding some more options to the getSummary() in paragraphs.

thenchev’s picture

Added more options for the summary: allowed bundles, number of allowed summaries and if the behavior summaries should be shown.

Now that we display count of how many children there are what would be the best way to show everything when we limit the number of summaries?

Here are some options how to display closed summary if for example we have 5 children but the limit is to show 2 summaries:

1) 2 children *show 2 summaries* // Show wrong count, probably not a good option.
2) More then 2 children *show 2 summaries* // This is how right now it is displayed.
3) 5 children *show 2 summaries* // Another option

Also is this going to be relevant when we change to icons?

Status: Needs review » Needs work

The last submitted patch, 19: consider_container-2852001-19.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 19: consider_container-2852001-19.patch, failed testing.

thenchev’s picture

Status: Needs work » Needs review

the bot is crazy

miro_dietiker’s picture

Status: Needs review » Needs work
+++ b/src/Entity/Paragraph.php
@@ -434,24 +441,33 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
-        $nested_summary = $this->getNestedSummary($field_name);
+        $nested_summary = $this->getNestedSummary($field_name, $allowed_bundles, $count_limit, $show_behavior_summary);

OK, you add new optional arguments to avoid breaking the contract.
But i requested other options we need to add in other issues - such as a recursion flag or keys of information that is covered in icons so the summary can skip it.
For less contract breaking, we proposed to have an $options array where we can pass in things with magic keys to also cover the other concepts.

I like the image showing "1 Children | and the summary..." but the vertical line got lost in the implementation?

Berdir’s picture

Yes, I already suggested on the original issue to add a empty $options argument so we can add additional options later on. I guess we now have to change the API, which is a bit unfortunate but only dev - > dev and not yet in a release.

Ginovski’s picture

1. Added options array instead of multiple arguments
2. Added a case for an empty nested.
3. Configured test accordingly.

Not sure why the edit button lowered a bit.

Status: Needs review » Needs work

The last submitted patch, 26: consider_container-2852001-26.patch, failed testing.

Ginovski’s picture

Fixed test fail and some minor changes.

Still has the problem with the lowered edit button.
Edit: This problem exists only in firefox, this issue does not affect it, maybe it is due some latest commits.

toncic’s picture

Status: Needs review » Needs work

Only small stuff.

  1. +++ b/src/Entity/Paragraph.php
    @@ -434,24 +441,35 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +  public function getSummary($options = []) {
    
    +++ b/src/ParagraphInterface.php
    @@ -24,9 +24,12 @@ interface ParagraphInterface extends ContentEntityInterface, EntityOwnerInterfac
    +  public function getSummary($options = []);
    

    I am thinking here to use $options = NULL instead of $options = [];

  2. +++ b/src/Entity/Paragraph.php
    @@ -434,24 +441,35 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +    if ($this->bundle() !== NULL && (is_array($allowed_bundles) && !in_array($this->bundle(), $allowed_bundles))) {
    

    I don't think we want grouping conditions.

  3. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +556,56 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +      return t('@summary', ['@summary' => $paragraph_summary]);
    

    I think is better to use $this->t();

Beside these, everything works fine.

Ginovski’s picture

Addressed #29:
1. Fixed the docs with array instead of NULL as default
2. Removed grouping conditions
3. $this->t was not available in the paragraph class

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +556,56 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +      return t('@summary', ['@summary' => $paragraph_summary]);
    

    That's not the proper use of a t().

  2. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +556,56 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +      return t('More then @count_limit children @summary', [
    

    A limit is to make sure things don't take too much space. It could lead to some "..." but it should never push a valuable summary text with meaningless prepended words.

+++ b/src/Entity/Paragraph.php
@@ -434,24 +441,35 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
+    $allowed_bundles = isset($options['allowed_bundles']) ? $options['allowed_bundles'] : NULL;

@@ -521,20 +556,56 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
+    if (isset($options['count_limit']) && $summary_count > $options['count_limit']) {

Both allowed bundles and count_limit are significantly pushing code complexity here.
But you neither use those nor test them. We don't want to have code complexit for hidden unneeded and undocumented features.

Ginovski’s picture

Status: Needs work » Needs review

1. Removed count limit and allowed bundles.
2. With 1, description for more than count_limit got removed as well.
3. Fixed the t(), maybe... I'm not sure if I did this correctly.

Also, a suggestion:
We could use 'elements' instead of 'children' in the summary

miro_dietiker’s picture

Status: Needs review » Needs work

Missing patch.

Ginovski’s picture

miro_dietiker’s picture

Status: Needs review » Needs work
Primsi’s picture

+++ b/src/Entity/Paragraph.php
@@ -521,20 +551,48 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
+   *   Array of paragraph options.

+++ b/src/ParagraphInterface.php
@@ -24,9 +24,12 @@ interface ParagraphInterface extends ContentEntityInterface, EntityOwnerInterfac
+   *   Array of paragraph options.

What are this options? This should be documented on the inteface for getSummary. The docblock for getNestedSummary can point to the getSummary on inteface for more information.

Shouldn't this new options be reflect on the formatter settings too? Should be that part of a follow up?

Ginovski’s picture

Addressed #36.
About the formatter, yes, that will be a follow-up. (I suppose there will be one for the test fix and one to add an additional option for the length of the summary (the truncate on 150 characters is not optimal in the library)).

miro_dietiker’s picture

Status: Needs review » Needs work
  1. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +551,50 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +      if (isset($value['entity'])) {
    ...
    +      // If we start with the closed summary the $value['entity'] is not
    +      // calculated so we load the entity ourselves.
    +      elseif (isset($value['target_id']) && isset($value['target_revision_id'])) {
    

    I guess these two cases are also present on other locations of the code. Usually, we should unify these conditions so code doesn't need to check it..? Don't know if it is possible.

  2. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +551,50 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +        if ($paragraph_entity instanceof ParagraphInterface) {
    ...
    +        if ($paragraph_entity) {
    

    First time you check for ParagraphsInterface, second time not.

This patch results in ALWAYS recursing deep over all children. In a setup with many nested paragraphs, it will significantly degrade performance, even if the children are collapsed. The subject asks to CONSIDER the children. We should not recurse if it is not needed. And i guess we should look at profiling data.

To limit recursion depth, we can not blindly pass the options array forward. Certain elements in it will need to be filtered / updated i guess. I was not sure if we should put the depth information into an argument?

Ginovski’s picture

1. Unified the two cases from #38 comment and checked for ParagraphsInterface accordingly.
2.Added new option depth_limit to limit the nesting summary (defaults to 1).
3.Added kernel test for the options array testing.

Berdir’s picture

Assigned: thenchev » Unassigned
Status: Needs review » Needs work

I need this for #2825575: Introduce a Drag & Drop Mode

  1. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +555,47 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +    // Decrease the depth, since we are entering a nested paragraph.
    +    $options['depth_limit'] = $options['depth_limit'] - 1;
    

    I think it would be more readable to do this on the call to this, where you can just do a 'depth_limit' => $depth_limit - 1

  2. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +555,47 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +      foreach ($this->{$field_name}->getValue() as $value) {
    +        if (isset($value['target_id']) && isset($value['target_revision_id'])) {
    +          $paragraph_entity = isset($value['entity']) ? $value['entity'] : $this->entityTypeManager()
    +            ->getStorage('paragraph')
    +            ->loadRevision($value['target_revision_id']);
    +          if ($paragraph_entity instanceof ParagraphInterface) {
    

    this can be simplified:

    * foreach $get($field_name) as $item
    * then $item->entity and so on. the original patch also on purpose did a ->entity check instead of id and then it automatically loads, so you can drop the whole loadRevision() fallback.
    * $paragraphs_entity => $paragraph or maybe $entity bcause we don't really know for sure if it's a paragraph yet at this point.

  3. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +555,47 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +    return \Drupal::translation()
    +      ->formatPlural($summary_count, '1 child@summary', '@count children @summary', [
    +        '@count' => $summary_count,
    +        '@summary' => $paragraph_summary,
    +      ]);
    

    I'm confused about this summary count thing. it adds quite a bit of complexity and it seems to be counting different kinds of children depending on depth?

    if we get the summary count from the children, then we count basically each field, including text fields a child? that doesn't make sense? and we count possibly multivalue paragraphs then again as just one child.

    My recommendation would be to always just look at the actual, direct children and not the grand children. Pretty sure this causes more confusion than it actually provides something useful?

  4. +++ b/src/ParagraphInterface.php
    @@ -24,9 +24,16 @@ interface ParagraphInterface extends ContentEntityInterface, EntityOwnerInterfac
    +   * @param array $options
    +   *   (optional) Array of additional options, with the following elements:
    +   *   - 'show_behavior_summary': Whether the summary should contain the
    +   *     behavior settings. TRUE enforces behavior settings in summary.
    +   *   - 'depth_limit': Depth limit of how many nested paragraph summaries are
    +   *     allowed.
    

    docs are unclear, doesn't say what is the default and what does "enforces behavior settings in summary" even mean? :)

Ginovski’s picture

Addressed #40
Extended text coverage with nested summary.

Status: Needs review » Needs work

The last submitted patch, 41: consider_container-2852001-41.patch, failed testing.

Ginovski’s picture

Primsi’s picture

Status: Needs review » Needs work

This needs a re-roll, apart from that looks quite ok.

Ginovski’s picture

Rerolled and fixed tests.

Primsi’s picture

Status: Needs review » Needs work

Just two more things.

  1. +++ b/src/Entity/Paragraph.php
    @@ -466,18 +481,38 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
    +  protected function getSummaryCount() {
    

    Is this still used somewhere?

  2. +++ b/src/Entity/Paragraph.php
    @@ -521,20 +556,34 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface, EntityN
        *   Short summary for nested paragraphs type.
    

    Or NULL if the summary is empty.

Ginovski’s picture

1. This wasn't used, so I removed it for now, we can add it, if we need it for extended summary.
2. Change the description accordingly.

  • Primsi committed 43621ad on 8.x-1.x authored by Ginovski
    Issue #2852001 by Ginovski, Denchev, miro_dietiker, Primsi, Berdir,...
Primsi’s picture

Status: Needs review » Needs work

Committed, thanks. Please add the follow up to make this configurable on the widget, then this can be moved to Fixed.

Ginovski’s picture

Status: Needs work » Fixed

Created follow-up #2890246: Make container summary configurable, setting this to fixed.

Status: Fixed » Closed (fixed)

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