Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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
Comment | File | Size | Author |
---|---|---|---|
#74 | interdiff-3012053-73-74.txt | 732 bytes | johnchque |
#74 | show_content_behavior_summary-3012053--74.patch | 64.96 KB | johnchque |
| |||
#73 | interdiff-3012053-72-73.txt | 721 bytes | johnchque |
#73 | show_content_behavior_summary-3012053--73.patch | 64.84 KB | johnchque |
| |||
#72 | interdiff-3012053-69-72.txt | 24.64 KB | johnchque |
Comments
Comment #2
johnchqueThis 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.
Comment #4
johnchqueNow hiding the content in the content tab. Not sure how to deal with the comma that connects both parts of the summary.
Comment #6
Berdirso 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.
Comment #7
miro_dietikerI 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.
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.
Comment #8
johnchqueWhile 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. :)
Comment #10
miro_dietikerWhat 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?
Comment #11
sasanikolic CreditAttribution: sasanikolic commentedI 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
Comment #12
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #14
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedHere are some screenshots.
Comment #15
miro_dietikerPlayed a bit around and i think we should do this:
Here some experiments but i'm not yet happy with it..
Comment #16
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedI addressed @miro_dietiker's feedback in this patch. We agreed to go with the 3rd solution, which looks the cleanest.
Comment #17
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #19
johnchqueIt 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.
Comment #20
miro_dietikerAbove 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!
Comment #21
miro_dietikerPromoting 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.
Comment #22
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedI 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:
Comment #23
johnchqueWorking on fixing tests.
Comment #24
johnchqueMade 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. :)
Comment #26
johnchqueWhile 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.
Comment #28
johnchqueFixing 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.
Comment #30
johnchqueFixing 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.
Comment #32
johnchqueThis should fix all the tests. It seems that Promoting to library is working as expected. :)
Comment #33
miro_dietikerThe behavior summary display is wrong if the behavior summary text contains a ",". We should keep arrays and not do implode / explodes with intermediate strings...
Comment #34
miro_dietikerChecked on mobile and we seem to have a bit too much vertical spacing. The extra large buttons add them, but not critical.
Comment #35
miro_dietikerChecked 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.
Comment #36
johnchqueOK, I think this is working. See:
Updated with the latest suggestion of @miro_dietiker.
Comment #37
miro_dietikerNow you should remove the left padding of the second line to keep them aligned.
Comment #38
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedSo, I found out that the cause of our issue lays in paragraphs_collection module, since we call
$plugin->settingsSummary($this)
fromParagraphsStylePlugin.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.
Comment #39
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedFor testing purposes, I also added a ","in the style plugin. Works fine.
Comment #40
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedReverted back the array_merge change, as we needed it more plugins are available.
Comment #41
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedComment #42
sasanikolic CreditAttribution: sasanikolic at MD Systems GmbH commentedAnd here is the paragraphs_collection followup: https://www.drupal.org/project/paragraphs_collection/issues/3029996
Comment #44
Berdirdebug leftover.
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.
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.
Comment #45
johnchqueSo 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?
So the code in the summary is a bit simpler I think.
Comment #47
BerdirI 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.
Comment #48
johnchqueUpdating 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?
Comment #50
johnchqueUpdating the test behaviors. :)
Comment #52
Berdircontent is an uncountable noun, so just content, not contents: https://dictionary.cambridge.org/grammar/british-grammar/content-or-cont...
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.
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.
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.
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.
Comment #53
johnchqueAddressing all suggestions of #52
Comment #55
johnchqueHad to use renderRoot.
Also, adding some white space control to avoid having extra large whitespaces in the label when promoting to the library.
Comment #57
BerdirrenderRoot() 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.
Comment #58
johnchqueIs it OK if we use getSummary in the formatter?
What about the classic widget?
Comment #60
johnchqueFixing more tests. Yes, it seems that renderPlain is the one to use. :)
Comment #62
johnchqueFixing more tests. Need to work on two things. Right now the tags, like iframe are not displayed properly.
Comment #64
johnchqueThis should fix all tests. Thanks @Berdir for the guidance.
Comment #66
johnchqueOh come on! This passes locally.
Comment #67
johnchqueMade some changes after discussion, since we added a right border for each behavior plugin we are able to drop the uppercase for labels.
Comment #69
johnchqueFixing tests. :)
Comment #70
johnchqueAdding follow-up.
Comment #71
Berdirwould 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:
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.');
$variables['expanded'] = !empty(..) should give you the same result?
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']
Instead of the loop, you can just do $content_summary_items += $entity->getSummaryItems($options)['content'];
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'
I think this could also use #theme paragraphs_summary, like the paragraphs widgets.
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.
Comment #72
johnchqueAddressing 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.
Comment #73
johnchqueAbout point 5, discussed with @Berdir, thanks! This works too. Still wondering about the labels. :)
Comment #74
johnchqueDiscussed about 1. Taking this direction.
Comment #75
BerdirGreat, committing. This is a big step in improving the summary.
Updating the issue title to reflect what we did here.