Problem/Motivation

When using perspectives, if we switch to the Behavior tab, we can lose control and focus over what Paragraph to edit.

Proposed resolution

Display the Content only summary when in Behavior tab.

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#74 interdiff-3012053-73-74.txt732 bytesjohnchque
#74 show_content_behavior_summary-3012053--74.patch64.96 KBjohnchque
#73 interdiff-3012053-72-73.txt721 bytesjohnchque
#73 show_content_behavior_summary-3012053--73.patch64.84 KBjohnchque
#72 interdiff-3012053-69-72.txt24.64 KBjohnchque
#72 show_content_behavior_summary-3012053--72.patch64.88 KBjohnchque
#69 interdiff-3012053-67-69.txt3.36 KBjohnchque
#69 show_content_behavior_summary-3012053--69.patch66.75 KBjohnchque
#67 Screenshot from 2019-02-08 12-33-13.png59.38 KBjohnchque
#67 interdiff-3012053-66-67.txt2.64 KBjohnchque
#67 show_content_behavior_summary-3012053--67.patch66.76 KBjohnchque
#66 interdiff-3012053-64-66.txt2.33 KBjohnchque
#66 show_content_behavior_summary-3012053--66.patch66.5 KBjohnchque
#64 interdiff-3012053-62-64.txt4.9 KBjohnchque
#64 show_content_behavior_summary-3012053--64.patch66.42 KBjohnchque
#62 interdiff-3012053-60-62.txt16.38 KBjohnchque
#62 show_content_behavior_summary-3012053--62.patch64.06 KBjohnchque
#60 interdiff-3012053-57-60.txt28.44 KBjohnchque
#60 show_content_behavior_summary-3012053--60.patch62.93 KBjohnchque
#58 interdiff-3012053-55-57.txt7.01 KBjohnchque
#58 show_content_behavior_summary-3012053--57.patch62.41 KBjohnchque
#55 interdiff-3012053-53-55.txt994 bytesjohnchque
#55 show_content_behavior_summary-3012053--55.patch61.61 KBjohnchque
#53 interdiff-3012053-50-53.txt12.6 KBjohnchque
#53 show_content_behavior_summary-3012053--53.patch61.55 KBjohnchque
#50 interdiff-3012053-48-50.txt1.29 KBjohnchque
#50 show_content_behavior_summary-3012053--50.patch59.76 KBjohnchque
#48 interdiff-3012053-45-48.txt4.2 KBjohnchque
#48 show_content_behavior_summary-3012053--48.patch58.1 KBjohnchque
#45 interdiff-3012053-40-45.txt13.7 KBjohnchque
#45 show_content_behavior_summary-3012053--45.patch57.5 KBjohnchque
#40 show_content_behavior_summary-3012053--40.patch52.78 KBsasanikolic
#39 Screenshot 2019-02-01 at 13.02.07.png47.81 KBsasanikolic
#38 Screenshot 2019-02-01 at 12.27.03.png62.73 KBsasanikolic
#38 show_content_behavior_summary-3012053--38-interdiff.txt1.73 KBsasanikolic
#38 show_content_behavior_summary-3012053--38.patch52.75 KBsasanikolic
#36 Screenshot from 2019-01-31 14-29-30.png33.49 KBjohnchque
#36 interdiff-3012053-32-36.txt6.07 KBjohnchque
#36 show_content_behavior_summary-3012053--36.patch52.76 KBjohnchque
#35 paragraphs-summary-hero-grey.png9.99 KBmiro_dietiker
#35 paragraph-summary-grey.png8.47 KBmiro_dietiker
#32 interdiff-3012053-30-32.txt8.35 KBjohnchque
#32 show_content_behavior_summary-3012053--32.patch51.36 KBjohnchque
#30 interdiff-3012053-28-30.txt13.48 KBjohnchque
#30 show_content_behavior_summary-3012053--30.patch51.59 KBjohnchque
#28 interdiff-3012053-26-28.txt4.75 KBjohnchque
#28 show_content_behavior_summary-3012053--28.patch49.53 KBjohnchque
#26 Screenshot from 2019-01-30 11-32-34.png15.12 KBjohnchque
#26 Screenshot from 2019-01-30 11-32-52.png15.96 KBjohnchque
#26 Screenshot from 2019-01-30 11-32-56.png51.62 KBjohnchque
#26 interdiff-3012053-24-26.txt16.72 KBjohnchque
#26 show_content_behavior_summary-3012053--26.patch48.23 KBjohnchque
#24 Screenshot from 2019-01-30 09-43-59.png18.63 KBjohnchque
#24 Screenshot from 2019-01-30 09-44-05.png21.09 KBjohnchque
#24 interdiff-3012053-16-24.txt4.17 KBjohnchque
#24 show_content_behavior_summary-3012053--24.patch43.06 KBjohnchque
#22 plugin name padding.png12.94 KBsasanikolic
#16 paragraph-behavior-open-styled.png96.25 KBsasanikolic
#16 paragraph-open-styled.png70.02 KBsasanikolic
#16 paragraphs-closed-styled.png116.01 KBsasanikolic
#16 show_content_behavior_summary-3012053-16-interdiff.txt40.08 KBsasanikolic
#16 show_content_behavior_summary-3012053--16.patch42.27 KBsasanikolic
#15 paragraphs-behavior-label.png8.84 KBmiro_dietiker
#15 paragraphs-behavior-border.png8.42 KBmiro_dietiker
#15 paragraphs-behavior-caps.png8.23 KBmiro_dietiker
#14 behavior summary.png101.83 KBsasanikolic
#14 behavior expanded.png157.59 KBsasanikolic
#14 paragraph expanded.png146.49 KBsasanikolic
#14 content summary.png67.99 KBsasanikolic
#11 show_content_behavior_summary-3012053-11-interdiff.txt9.62 KBsasanikolic
#11 show_content_behavior_summary-3012053-11.patch10.29 KBsasanikolic
#8 interdiff-3012053-4-8.txt2.42 KBjohnchque
#8 show_content_behavior_summary-3012053-8.patch6.13 KBjohnchque
#4 interdiff-3012053-2-4.txt1022 bytesjohnchque
#4 show_content_behavior_summary-3012053-4.patch5.06 KBjohnchque
#2 Screenshot from 2018-11-07 12-41-40.png64.65 KBjohnchque
#2 Screenshot from 2018-11-07 12-41-45.png45.26 KBjohnchque
#2 show_content_behavior_summary-3012053-2.patch4.81 KBjohnchque
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yongt9412 created an issue. See original summary.

johnchque’s picture

This patch changes a lot the structure of the summary but allows to have a better overview of its elements.

Still need to work on hiding in the Content tab.

Status: Needs review » Needs work

The last submitted patch, 2: show_content_behavior_summary-3012053-2.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review
FileSize
5.06 KB
1022 bytes

Now hiding the content in the content tab. Not sure how to deal with the comma that connects both parts of the summary.

Status: Needs review » Needs work

The last submitted patch, 4: show_content_behavior_summary-3012053-4.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

+++ b/src/Entity/Paragraph.php
@@ -492,18 +493,23 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
 
-    $collapsed_summary_text = implode(', ', $summary);
-    return strip_tags($collapsed_summary_text);
+    $collapsed_summary_text = implode(', ', $summary_text);
+    return $collapsed_summary_text;
   }

so this comma is the problem?

Can we solve this with css? Either by using CSS to display a visual comma, or just use some other visual separator in case both elements are displayed.

miro_dietiker’s picture

I thought this issue is really only about setting an initial CSS state.
We are now half refactoring something that is not yet really where we want to be in the end.

+++ b/src/Entity/Paragraph.php
@@ -492,18 +493,23 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
       foreach ($paragraphs_type->getEnabledBehaviorPlugins() as $plugin_id => $plugin) {
...
+          $plugins_summary = array_merge($plugins_summary, $plugin_summary);
...
+      $text_plugins_summary = implode(', ', $plugins_summary);
+      $summary_text[] = '<span class="summary-plugin">' . $text_plugins_summary . '</span>';
...
+    $collapsed_summary_text = implode(', ', $summary_text);

In fact i think the goal should be to have a render element per plugin summary. Or one element that renders all behavior summary items at once. We would then drop all implodes by comma. Instead each behavior summary item would get some other visual separator and a class according to the behavior plugin name.

I previously thought it's an overkill, but we need this level of semantics in the summary to improve the summary styling for making it easier to read.

The best fitting element in standard design best practices was the material.io chips:
https://material.io/design/components/chips.html#
We need to be carefully to not make it look too much like a button.
We would either need an icon per behavior plugin or output them in two lines: behavior plugin name as overline and its status as regular chip content.

Do we really want to refactor this here?
I also couldn't find an existing open issue around that..
However chances are that before we implement this, someone needs to do a mockup and a screendesign.

johnchque’s picture

While I agree with @miro_dietiker, I also don't just want to delete the changes I made. Updating new patch that makes the coma between content and behavior be added by CSS.

BUT I see a problem now with the current approach, I first add hidden-tabs class to the paragraphs container and remove it when expand them all, the problem comes when I Edit All and I close one of the Paragraphs, as previously we weren't using css to hide any part of the summary, that wasn't a problem and the summary was displayed as desired. Now, even if we are just closing one Paragraph, the content part is hidden if we are in the Content tab (As this was the expected behavior for the open paragraphs).

Now, about the Chip element, I think it was created to encourage interaction by clicking it, I think if we just set the cursor as the normal arrow when hovering, that shouldn't be a problem. :)

Status: Needs review » Needs work

The last submitted patch, 8: show_content_behavior_summary-3012053-8.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

miro_dietiker’s picture

What i don't understand is: If we have a toggle class like .content-active and .behavior-active.. Why do we additionally need to call .show() .hide() ? The visibility can already be managed through CSS based on the toggle class.

Or does .show() / .hide() also have some additional accessibility integration?

sasanikolic’s picture

I did some code refactoring and fixes to John's patch.

1.) paragraphs-description contains general description styling
2.) add paragraphs-collapsed-description only when the paragraph is collapsed, so with that we can style it correctly
3.) when on content tab and paragraph is closed, display content + behavior summary, when it's collapsed, display only the behavior
4.) vice versa on the behavior tab
5.) change the comma to semicolon - i believe this is a better indicatior of separating two descriptions, although not optimal and we should find a better UX solution

sasanikolic’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 11: show_content_behavior_summary-3012053-11.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

sasanikolic’s picture

Here are some screenshots.

miro_dietiker’s picture

Played a bit around and i think we should do this:

  • Limit the summary to the current level only in case the Paragraph is expanded. Thus avoid duplications like behavior%20expanded.png
  • Limit the summary text to the first line.
  • Put Paragraphs behavior summary to the second line (if collapsed)
  • We need a dom element per behavior summary item, not one for all combined. Maybe we even need a separate element for each the label to apply theming.
  • Put Paragraphs behavior summary to the second line (if collapsed)
  • Separate the behavior summary elements with padding, not a character like ";"
  • Make the behavior summary text a bit smaller

Here some experiments but i'm not yet happy with it..

sasanikolic’s picture

I addressed @miro_dietiker's feedback in this patch. We agreed to go with the 3rd solution, which looks the cleanest.

sasanikolic’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 16: show_content_behavior_summary-3012053--16.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

It looks certainly really good! I think the summary text can be gray too? And also add some small padding to the .summary-plugin element, like 2px?

I believe we will need to rework a lot of our tests since the summary structure is changing with this approach.

miro_dietiker’s picture

Above you accidentally dropped the comma in the content (missing!) but added the comma to the summary plugins (not needed).

I think i would also put the edit button to the baseline instead of vertically centering.
The grey BG definitively need a bit of padding.
I had a slightly bigger padding separating each behavior summary.

And yeah, there is good consistency now, but that IMHO results in too much uniformity.
In my tiny screens above i applied grey text color intentionally to the behavior summary text to lower the priority.

We need to check the output combined with icons - they can be left (e.g. change) and right (e.g. lock) of the summary!

miro_dietiker’s picture

Priority: Normal » Major

Promoting priority as this is changing our summary DOM structure and we want this to be stable as soon as possible.
EDIT: And also because it is IMHO majorly improving the UI as a long awaited summary iteration.

sasanikolic’s picture

FileSize
12.94 KB

I added the padding to the plugin name initially, but that resulted in misalignment with the content summary and was ugly. I can easily re-add that tho.

For example, see here:

johnchque’s picture

Assigned: Unassigned » johnchque

Working on fixing tests.

johnchque’s picture

Made some small changes here. Now it looks like:

Will continue working on the tests. BTW @miro_dietiker, Sasa did not remove the coma for the content, it is still present is just added first. :)

Status: Needs review » Needs work

The last submitted patch, 24: show_content_behavior_summary-3012053--24.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

While fixing tests I have noticed an important problem. :(

Having the following structure:

If the children paragraphs have no behaviors set at all, the summary is displayed correctly:

However, once we set a behavior plugin to the first children, the summary has the following problem:

Because all summary elements are added after the previous paragraph. Not completely sure how to deal with this. I think we can try to have two arrays, one for content only and other for plugins only? Not sure.

Status: Needs review » Needs work

The last submitted patch, 26: show_content_behavior_summary-3012053--26.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Fixing more tests. :) Discussed about the summary problem. We cannot make much context by including behavior plugins in parent summaries, so removing just to keep the children content. :)

EDIT: Also added an extra implode since we were just displaying one plugin if there were more. That fixes it and keeps compatibility with the style plugin.

Status: Needs review » Needs work

The last submitted patch, 28: show_content_behavior_summary-3012053--28.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Fixing more tests. Found a problem when promoting to library, should be better now.

Saw a small problem with the library item summary, will confirm tomorrow.

Status: Needs review » Needs work

The last submitted patch, 30: show_content_behavior_summary-3012053--30.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review
FileSize
51.36 KB
8.35 KB

This should fix all the tests. It seems that Promoting to library is working as expected. :)

miro_dietiker’s picture

Status: Needs review » Needs work

The behavior summary display is wrong if the behavior summary text contains a ",". We should keep arrays and not do implode / explodes with intermediate strings...

miro_dietiker’s picture

Checked on mobile and we seem to have a bit too much vertical spacing. The extra large buttons add them, but not critical.

miro_dietiker’s picture

Checked a bit what patterns can be used here and ended up here:
https://material.io/design/components/lists.html#implementation

As you can see, they use often grey and a bit smaller font to make an item secondary.
The grey we have is still putting (too much) focus on the labels, that's why we tested further and ended up with this:

Making a label uppercase is also a common pattern with fieldsets (node edit sidebar, admin/config grouping).

I think this is the most balanced solution we have currently.

While on it, the child count badge (4) doesn't reserve a min-size, so horizontal indentation of the summary varies. Also it has some padding problem, making it look unbalanced.

johnchque’s picture

OK, I think this is working. See:

Updated with the latest suggestion of @miro_dietiker.

miro_dietiker’s picture

Status: Needs review » Needs work

Now you should remove the left padding of the second line to keep them aligned.

sasanikolic’s picture

So, I found out that the cause of our issue lays in paragraphs_collection module, since we call $plugin->settingsSummary($this) from ParagraphsStylePlugin.php. What I did there, was to render the summary array instead of imploading it by comma, and that worked fine. I believe we should render the strings also in settingsSummary() in ParagraphsGridLayoutPlugin.php. We could also fix that in paragraphs, but it would just add complexity...

Not sure how to proceed there, since it's a separate module?

I did some small code fixes and fixed the styles.
I'm also attaching how the summary looks with my changes in paragraphs_collection.

sasanikolic’s picture

For testing purposes, I also added a ","in the style plugin. Works fine.

sasanikolic’s picture

Reverted back the array_merge change, as we needed it more plugins are available.

sasanikolic’s picture

Status: Needs work » Needs review
sasanikolic’s picture

And here is the paragraphs_collection followup: https://www.drupal.org/project/paragraphs_collection/issues/3029996

The last submitted patch, 38: show_content_behavior_summary-3012053--38.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php
    @@ -167,12 +167,13 @@ JS;
         $save_button->press();
         $this->waitForAjaxToFinish();
    -    $this->assertRaw('class="paragraphs-collapsed-description">This is a reusable text UPDATED.');
    +    //debug($this->getSession()->getPage()->getContent());
    +    $this->assertRaw('class="paragraphs-description"><div class="paragraphs-summary-wrapper">This is a reusable text UPDATED.');
         $this->submitForm([], 'Save');
         // Edit the outside library item.
    

    debug leftover.

  2. +++ b/src/Entity/Paragraph.php
    @@ -481,17 +482,43 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
    +    $content_text_summary = implode(', ', $summary);
    +    // Wrap only inner summary items.
    +    if ($content_text_summary != '') {
    +      if ($depth_limit !== 0) {
    +        $summary_text[] = '<div class="paragraphs-summary-wrapper">' . $content_text_summary . '</div>';;
    +      }
    +      else {
    +        $summary_text[] = '<span class="summary-content">' . $content_text_summary . '</span>';
    +      }
    +    }
    

    I think this is easier if we do "if ($summary) and then implode inside.

    I also think we should try to find a way to postpone the HTML wrappers until later. and not make them part of the array contents.

    For a start, I would nest the $summary array from the start, initialize it as $summary = ['content' => [], 'behaviors' => []], then put the parts inside those sub-keys.

    The depth check here also assumes that there is only 1 and 0, if you'd getSummary() with depth = 2, you'd get two div wrappers. so we might want to instead add an explicit nested = TRUE settingo the array and then do empty($options['nested']) instead of this.

  3. +++ b/src/Entity/Paragraph.php
    @@ -481,17 +482,43 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
    +      if (!empty($plugins_summary)) {
    +        $wrap_plugins = function($plugin_summary_item) {
    +          $exploded_plugin = explode(': ', $plugin_summary_item);
    +          $exploded_plugin[0] = '<span class="summary-plugin-label">' . $exploded_plugin[0] . '</span>';
    +
    +          $wrapped_plugin = implode(' ', $exploded_plugin);
    +          return '<span class="summary-plugin">' . $wrapped_plugin . '</span>';
    +        };
    +
    +        $wrapped_plugins = array_map($wrap_plugins, $plugins_summary);
    +
    +        $text_plugins_summary = implode(' ', $wrapped_plugins);
    +        $summary_text[] = '<div class="paragraphs-plugin-wrapper">' . $text_plugins_summary . '</div>';
    +      }
    

    Instead of adding magic splits, why don't we add a explicit, optional support for nested arrays with label => value, we need to update the plugins anyway. Style would return something like this then:

    <?php
    [ ['label' => 'Group A', 'value' => 'Selected Style'], ['label' => 'Group B', 'value' => 'Another style']]

    Thinking more about this, we could then also make the top-level a render array with a template and a #content and #behaviors and a #theme => 'paragraphs_summary' as well as #nested. The whole HTML juggling could then be done in a single twig template.

    In there, we'd loop first over content items if there are any and second over behaviors, the content of these can then be checked with https://twig.symfony.com/doc/1.x/tests/iterable.html, and if an array, assume it has label/value keys, making the span structure explicit.

    not 100% sure yet how the nested part would work, as optimally, we'd only have a single-top level template, that would also deal with the nested stuff. We could add a new public method getContentSummaryTexts($options) that returns just an array of strings and merge them together.

johnchque’s picture

So I added a twig template where all the classing is made. I updated some styles to be a bit more semantic and moved everything to use arrays.

One big question. When we have plugins that just return one element (unlike Styles) should we make that all of them return an array with the following structure?

return [
        [
          'label' => $this->t('Anchor'),
          'value' => 'scrollto-' . $anchor
        ]
      ];

So the code in the summary is a bit simpler I think.

Status: Needs review » Needs work

The last submitted patch, 45: show_content_behavior_summary-3012053--45.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

I think it is important that it doesn't *break*, but we don't have to be very nice to them, if the summary item is not an array again, just set it as ['value' => $summary_part] and in twig, support that the label is empty by not printing the wrapper.

johnchque’s picture

Updating the code a bit. Addressing the comment in #47.

There are few things that I would like to know if everyone agrees:
- Is it OK to add the coma with CSS?
- I added some foreachs there because array_merge or + check the keys and they do not work well with nested summaries, is that ok?
- We need to add an extra wrapper of array to the plugin summary is that OK? Because the style plugin return 2 elements there and the others only one.

EDIT
Also, I've just realized that the changes I made create a different structure for the summary, where each field creates a new summary-content wrapper even if they are in the same Paragraph. Is that OK too?

Status: Needs review » Needs work

The last submitted patch, 48: show_content_behavior_summary-3012053--48.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Updating the test behaviors. :)

Status: Needs review » Needs work

The last submitted patch, 50: show_content_behavior_summary-3012053--50.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

  1. +++ b/src/Entity/Paragraph.php
    @@ -429,23 +429,23 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
             if ($file_summary != '') {
    -          $summary[] = $file_summary;
    +          $summary['contents'][] = $file_summary;
             }
    

    content is an uncountable noun, so just content, not contents: https://dictionary.cambridge.org/grammar/british-grammar/content-or-cont...

  2. +++ b/src/Entity/Paragraph.php
    @@ -429,23 +429,23 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
             ]);
             if ($nested_summary != '') {
    -          $summary[] = $nested_summary;
    +          $summary = array_merge($summary, $nested_summary);
             }
    

    the != '' check is pretty strange, I don't think it is ever a string now? (just always return an array and you can remove the condition here.

    also, I think you can change getNestedSummary() to only return a flat list for the content and just merge that. because that array_merge() will not do what you think it does.

  3. +++ b/src/Entity/Paragraph.php
    @@ -485,13 +485,17 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
     
    -    $collapsed_summary_text = implode(', ', $summary);
    -    return strip_tags($collapsed_summary_text);
    +    return $summary;
    

    this changes the return value of this method to return an array, which is causing a ton of test fails as you can see.

    We don't want to introduce an API change to the outside. You want to define the render array here, render it and then return the rendered string.

  4. +++ b/src/Entity/Paragraph.php
    @@ -638,32 +642,31 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
               // Switch to the entity translation in the current context if exists.
               $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $this->activeLangcode);
    -          $summary[] = $entity->getSummary($options);
    +          $entity_summary = $entity->getSummary($options);
    +          foreach ($entity_summary['contents'] as $content) {
    +            $summary['contents'][] = $content;
    +          }
    +          foreach ($entity_summary['behaviors'] as $behaviors) {
    +            $summary['behaviors'][] = $behaviors;
    +          }
               $this->summaryCount++;
             }
    

    the problem then of course is this part.

    That is why I suggested to add a new public method that is named getContentSummaryParts() or so, that returns just the stuff that goes into 'content', then you call that here and not getSummary(). Basically, we'd refacter the part of getSummary() that sets all the keys in content into that new method.

    Another option would be to add a new setting that changes the return value, but that is generally considered to be bad design and an anti-pattern.

  5. +++ b/src/Plugin/Field/FieldWidget/ParagraphsWidget.php
    @@ -834,9 +851,9 @@ class ParagraphsWidget extends WidgetBase {
                   $element['top']['summary']['fields_info'] = [
    -                '#markup' => $summary,
    -                '#prefix' => '<div class="paragraphs-collapsed-description">',
    -                '#suffix' => '</div>',
    +                '#theme' => 'paragraphs_summary',
    +                '#summary' => $summary,
    +                '#expanded' => FALSE,
                     '#access' => $paragraphs_entity->access('update') || $paragraphs_entity->access('view'),
    

    I see that defining it like this when we can is cleaner than having to go through a #markup again. Yet another idea would be this:

    We add getSummaryItems(), that is basically what getSummary() is now, and then re-add getSummary() that just calls getSummaryItems() and renders it into a string.

johnchque’s picture

Addressing all suggestions of #52

Status: Needs review » Needs work

The last submitted patch, 53: show_content_behavior_summary-3012053--53.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Had to use renderRoot.

Also, adding some white space control to avoid having extra large whitespaces in the label when promoting to the library.

Status: Needs review » Needs work

The last submitted patch, 55: show_content_behavior_summary-3012053--55.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Berdir’s picture

renderRoot() is definitely wrong, if anything then renderPlain()

Looks like you still have quite a few places where you now try to use the result of getSummary() as an array or so, either update that or use getSummaryItems() instead.

johnchque’s picture

Is it OK if we use getSummary in the formatter?

What about the classic widget?

Status: Needs review » Needs work

The last submitted patch, 58: show_content_behavior_summary-3012053--57.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Fixing more tests. Yes, it seems that renderPlain is the one to use. :)

Status: Needs review » Needs work

The last submitted patch, 60: show_content_behavior_summary-3012053--60.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Fixing more tests. Need to work on two things. Right now the tags, like iframe are not displayed properly.

Status: Needs review » Needs work

The last submitted patch, 62: show_content_behavior_summary-3012053--62.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

This should fix all tests. Thanks @Berdir for the guidance.

Status: Needs review » Needs work

The last submitted patch, 64: show_content_behavior_summary-3012053--64.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Oh come on! This passes locally.

johnchque’s picture

Made some changes after discussion, since we added a right border for each behavior plugin we are able to drop the uppercase for labels.

Status: Needs review » Needs work

The last submitted patch, 67: show_content_behavior_summary-3012053--67.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

johnchque’s picture

Status: Needs work » Needs review
FileSize
66.75 KB
3.36 KB

Fixing tests. :)

johnchque’s picture

Berdir’s picture

Status: Needs review » Needs work
  1. +++ b/modules/paragraphs_library/src/Entity/LibraryItem.php
    @@ -283,7 +283,7 @@ class LibraryItem extends EditorialContentEntityBase implements LibraryItemInter
        */
       protected static function buildLabel(ParagraphInterface $paragraph) {
         $summary = $paragraph->getSummary(['show_behavior_summary' => FALSE]);
    -    $summary = Unicode::truncate($summary, 50);
    +    $summary = Unicode::truncate(strip_tags($summary), 50);
         return $paragraph->getParagraphType()->label() . ': ' . $summary;
       }
    

    would it make sense to use getSummaryItems() here?

    It's not simpler, but we avoid having to render it with twig and then dropping the html tags again:

    $summary = $paragraph->getSummaryItems(['show_behavior_summary' => FALSE]);
        $summary = Unicode::truncate(implode(', ', $summary), 50);
    
  2. +++ b/modules/paragraphs_library/tests/src/FunctionalJavascript/ParagraphsLibraryItemEntityBrowserTest.php
    @@ -167,12 +167,12 @@ JS;
         $save_button->press();
         $this->waitForAjaxToFinish();
    -    $this->assertRaw('class="paragraphs-collapsed-description">This is a reusable text UPDATED.');
    +    $this->assertRaw('class="paragraphs-description paragraphs-collapsed-description"><div class="paragraphs-content-wrapper"><span class="summary-content">This is a reusable text UPDATED.</span>');
         $this->submitForm([], 'Save');
    

    not sure if we need to be that specific. And since this is a FunctionalJavascript test, we could actually do this more easily with CSS selectors: $this->assertSession()->elementContains('css', '.paragraphs-description .summary-content', 'This is a reusable text UPDATED.');

  3. +++ b/paragraphs.module
    @@ -590,3 +594,18 @@ function _paragraphs_migration_entity_type_adjust(array &$migration, $destinatio
    +  $variables['expanded'] = isset($variables['element']['#expanded']) ? $variables['element']['#expanded'] : FALSE;
    

    $variables['expanded'] = !empty(..) should give you the same result?

  4. +++ b/src/Entity/Paragraph.php
    @@ -408,10 +409,54 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
    +   * @return array
    +   *   An keyed array with all content and behavior items of the summary.
    +   */
    +  protected function getContentSummaryItems($depth_limit = 1) {
         $summary = [];
    

    Now we have 3 different methods. I wondering if we can inline this back into getSummaryItems() now.

    Instead of using getContentSummaryItems(), we should be able to use getSummaryItems()['content']

  5. +++ b/src/Entity/Paragraph.php
    @@ -638,32 +670,27 @@ class Paragraph extends ContentEntityBase implements ParagraphInterface {
               $entity = \Drupal::service('entity.repository')->getTranslationFromContext($entity, $this->activeLangcode);
    -          $summary[] = $entity->getSummary($options);
    +          $content_summary_items = $entity->getContentSummaryItems($options['depth_limit']);
    +          foreach ($content_summary_items as $content_summary_item) {
    +            $summary_content[] = $content_summary_item;
    +          }
               $this->summaryCount++;
             }
    

    Instead of the loop, you can just do $content_summary_items += $entity->getSummaryItems($options)['content'];

  6. +++ b/src/ParagraphInterface.php
    @@ -47,11 +47,27 @@ interface ParagraphInterface extends ContentEntityInterface, EntityOwnerInterfac
    +   *
    +   * @return array
    +   *   An keyed array with all content and behavior items of the summary.
    +   */
    +  public function getSummaryItems(array $options = []);
    

    this could be a bit clearer on what array keys it actually returns, it's not behavior or behavior items but behaviors. something like "A list of summary items, grouped into the keys 'content' and 'behaviors'

  7. +++ b/src/Plugin/Field/FieldFormatter/ParagraphsSummaryFormatter.php
    @@ -48,9 +47,7 @@ class ParagraphsSummaryFormatter extends EntityReferenceFormatterBase {
             $elements[$delta]['summary']['description'] = [
    -          '#markup' => $summary,
    -          '#prefix' => '<div class="paragraphs-collapsed-description">',
    -          '#suffix' => '</div>',
    +          '#markup' => $entity->getSummary()
             ];
    

    I think this could also use #theme paragraphs_summary, like the paragraphs widgets.

  8. +++ b/src/Tests/Classic/ParagraphsEditModesTest.php
    @@ -85,7 +85,7 @@ class ParagraphsEditModesTest extends ParagraphsTestBase {
         $this->clickLink(t('Edit'));
    -    $this->assertRaw('<div class="paragraphs-collapsed-description">text_summary');
    

    these tests can't use the nicer asserts yet, but we could make it less specific and just look for text_summary. All we care about here IMHO is that it is the summary and it is less likely to break if we make changes to the template.

johnchque’s picture

Status: Needs work » Needs review
FileSize
64.88 KB
24.64 KB

Addressing suggestions of the previous comment:
1. Wondering if when promoting to library we consider behaviors too? What if a paragraph does not have content but just behaviors set? I kept it as it was for now. Otherwise we would need to either implode each item on the content and behavior keys and then implode both parts.
2. Done.
3. Done.
4. Done.
5. Not possible I think, since getting the 'content' array will return a flat list, adding with + will not append when we have two arrays with keys "0". See: https://stackoverflow.com/questions/2140090/operator-for-array-in-php. I kept the loop. Maybe I am wrong.
6. Done.
7. Done.
8. Done. Updated to just check one tag, I think we should still check if they are part of the summary or they are displayed in the content.

johnchque’s picture

About point 5, discussed with @Berdir, thanks! This works too. Still wondering about the labels. :)

johnchque’s picture

Discussed about 1. Taking this direction.

Berdir’s picture

Title: Show content only summary when switched to behavior tab » Split summary into content and behavior parts, show content/behavior only summary when switching between content and behaviors
Status: Needs review » Fixed

Great, committing. This is a big step in improving the summary.

Updating the issue title to reflect what we did here.

  • Berdir committed a69f72d on 8.x-1.x authored by yongt9412
    Issue #3012053 by yongt9412, sasanikolic, miro_dietiker, Berdir: Split...

Status: Fixed » Closed (fixed)

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