Problem/Motivation

In views module there are some collapsible details elements that are displayed empty at the moment.

A views modal with a closed More fieldset

A views modal with an open but empty More fieldset

For example: Having moved the "administrative title" field (as in Views 7.x) to its own collapsible details, the section "More" does not contain any options in most cases.

Lookin into this issue we found a problem in the views module: It still uses its own logic to group widgets ('#fieldset') -- while most of the containers already have been converted to details elements.

The details element has a mechanism to hide empty fieldsets, but it does not work for direct children in the container element.

Proposed resolution

We decided to fix the UI problem by using the available option on the details container. Removing all fieldset logic is out of scope for this issue here.

A views modal with no More fieldset

Remaining tasks

none.

Original report by @hexabinaer

CommentFileSizeAuthor
#99 views-more-3.png30.47 KBtstoeckler
#99 views-more-2.png30.71 KBtstoeckler
#99 views-more-1.png30.48 KBtstoeckler
#85 hide_empty_details-2409639-85.patch8.53 KBk4v
#84 assert_more_is_absent.patch685 bytesk4v
#75 hide_empty_details-2409639-75.patch7.86 KBk4v
#72 hide_empty_details-2409639-72.patch18.33 KBk4v
#71 hide_empty_details-2409639-71.patch19.81 KBk4v
#68 hide_empty_details-2409639-67.patch23.64 KBmadhavvyas
#67 hide_empty_details-2409639-66.patch583.91 KBmadhavvyas
#62 hide_empty_details-2409639-62.patch23.52 KBmadhavvyas
#57 hide_empty_details-2409639-57.patch13.89 KBk4v
#53 hide_empty_details-2409639-53.patch13.14 KBk4v
#50 hide_empty_details-2409639-49.patch12.66 KBk4v
#48 hide_empty_details-2409639-48.patch11.81 KBk4v
#35 hide_collapsible-2409639-35.patch10.14 KBk4v
#31 hide_collapsible-2409639-31.patch10.18 KBk4v
#24 hide_collapsible-2409639-24.patch11.53 KBk4v
#21 hide_collapsible-2409639-19.patch11.55 KBk4v
#17 hide_collapsible-2409639-17.patch11.45 KBk4v
#14 hide_collapsible-2409639-14.patch377.34 KBk4v
#9 hide_collapsible-2409639-9.patch7.18 KBk4v
#1 hide_more_collapsible_if_empty-2409639-1.patch920 byteskatzilla
hide_fieldset_more_if_empty.png51.55 KBhexabinaer
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

katzilla’s picture

added patch.

katzilla’s picture

Status: Active » Needs review
k4v’s picture

.

k4v’s picture

Issue summary: View changes

Status: Needs review » Needs work

The last submitted patch, 1: hide_more_collapsible_if_empty-2409639-1.patch, failed testing.

hexabinaer’s picture

Title: Hide collapsible fieldset "More" if empty » Hide collapsible fieldsets if empty
Assigned: hexabinaer » Unassigned

Ooops, seems to be more complicated than I thought. Please provide summary of sprint weekend findings/discussions. I know of:
* should be solved programmatically (thus: issue title changed)

Settings this to unassigned, for I am not the one capable of solving. katzilla and k4v are working on it.

k4v’s picture

Assigned: Unassigned » k4v
dawehner’s picture

It would be great if someone could post a screenshot of what we are talking here

k4v’s picture

Another try.

k4v’s picture

Status: Needs work » Needs review
dawehner’s picture

+++ b/core/modules/views/src/Plugin/views/argument/ManyToOne.php
@@ -72,7 +72,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
       '#default_value' => !empty($this->options['break_phrase']),
-      '#fieldset' => 'more',
+      '#group' => 'more',
     );

Its great to see that we finally have an api for that in core. ... so can we remove the preRender function from views after that?

k4v’s picture

This was quite confusing. I still wonder, why I have to set '#parents' => array('more') on the details element.

tstoeckler’s picture

@k4v: Awesome idea using #parents, nice one!

Re #11: Yes, in theory we can remove PluginBase::preRenderAddFieldsetMarkup() and all of it's usages now, I think.

k4v’s picture

oops

Status: Needs review » Needs work

The last submitted patch, 14: hide_collapsible-2409639-14.patch, failed testing.

k4v’s picture

k4v’s picture

Here's a new version with all the fieldset stuff removed.

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 17: hide_collapsible-2409639-17.patch, failed testing.

dawehner’s picture

Assigned: k4v » Unassigned
Issue tags: +VDC

Really nice cleanup! Sadly still a php error :)

k4v’s picture

Once again.

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 21: hide_collapsible-2409639-19.patch, failed testing.

k4v’s picture

lets try this....

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: hide_collapsible-2409639-24.patch, failed testing.

tstoeckler’s picture

@k4v: The patch looks great. Two things are making the tests fail, apparently:
1. FilterPluginBase (line 518) and SortPluginBase (line 205) expect #pre_render to be set, which is no longer the case so that leads to PHP errors.
2. The tests rely on the #parents form structure to set the form values, so they are trying to set form values of the form options[foo][bar] when it should now be just foo[bar] because we have explicitly removed options from the parents. See the test results for exactly where that happens.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 24: hide_collapsible-2409639-24.patch, failed testing.

k4v’s picture

I did some research on the subject "fieldset vs details" in the issue queue.

'type' => 'fieldset' has been widely replaced by 'type' => 'details': https://www.drupal.org/node/1168246

Views uses a strange mixture of both at the moment: The '#fieldset' property is a special thing views does to sort the leaf elements into the 'fieldsets', but in our case it has already been replaced with a 'details' container element.

What I did in #9 is not the right thing. The #group property is only valid for elements of type details and fieldset, not for the leaf elements.

k4v’s picture

Another approach. To remove the #fieldset logic complete should be a new issue.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Render/Element/Details.php
@@ -64,10 +64,12 @@ public static function preRenderDetails($element) {
+      if (empty(Element::getVisibleChildren($element)) && Details::groupHasNoChildren($element)) {

@@ -75,4 +77,20 @@ public static function preRenderDetails($element) {
+  private static function groupHasNoChildren($element) {

note: better use static::groupHasNoChildren and protected. This makes it al little bit easier to override the logic in a subclass.

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: hide_collapsible-2409639-31.patch, failed testing.

k4v’s picture

Status: Needs work » Needs review
FileSize
10.14 KB
Gábor Hojtsy’s picture

  1. +++ b/core/lib/Drupal/Core/Render/Element/Details.php
    @@ -64,15 +64,33 @@ public static function preRenderDetails($element) {
    +    // TODO: Is there a use case to display empty details? If not we could
    +    // remove the #optional property.
    

    Looks like this needs resolved before this may land.

  2. +++ b/core/lib/Drupal/Core/Render/Element/Details.php
    @@ -64,15 +64,33 @@ public static function preRenderDetails($element) {
    +  protected static function groupHasNoChildren($element) {
    +    if (isset($element['#parents'])) {
    +      $group = implode('][', $element['#parents']);
    +      $children = Element::getVisibleChildren($element['#groups'][$group]);
    +      return empty($children);
    +    }
    +    return FALSE;
    

    Is it true if it does not have parents, it does not have children either?

tstoeckler’s picture

The #group property is only valid for elements of type details and fieldset, not for the leaf elements.

That is not true. See NodeForm for proof. I think #24 was really close and preferable to the current patch.

k4v’s picture

See: https://api.drupal.org/api/drupal/developer%21topics%21forms_api_referen...

Searching for '#type'=>'details' I see in almost all of the examples that the children are added to the details directly.

=). I still like #35 better -- why not put the leaf elements right there where they belong?

tstoeckler’s picture

Re #36.2: The check for the children that are directly contained in the element is done prior to that check: $children = Element::getVisibleChildren($element); if (empty($children) ...). This is not very intuitive (not @k4v's fault, but Form API's), but it's correct. At least I think it makes sense. This needs an issue summary update, I hope I get to that later today. I will also try to polish the inline code-comments a bit and open some follow-ups for this.

Most importantly this needs review from a Views maintainer. I don't know why the fieldset dance was originally introduced into Views, so we should check before altering it. Not sure how old this is in Views (so maybe only @dawehner can help here?) but I will ping someone on the VDC team to have a look at this.

k4v’s picture

Title: Hide collapsible fieldsets if empty » Hide empty details containers
Issue summary: View changes
k4v’s picture

Issue summary: View changes
dawehner’s picture

Most importantly this needs review from a Views maintainer. I don't know why the fieldset dance was originally introduced into Views, so we should check before altering it. Not sure how old this is in Views (so maybe only @dawehner can help here?) but I will ping someone on the VDC team to have a look at this.

Well, this dance was introduced in order to decouple the rendered form structure from the form structure/parents structure itself.

tstoeckler’s picture

@dawehner: So that means you (also) prefer to go back to the patch in #24?

k4v’s picture

Another simpler variant would be to use the #group property (like in #24) and set it to '#group' => 'options][more'.

This is the most simple thing to do, then we don't need to change the #parent structure, and the logic for #optional shuld work. It's done like this in several places, like CKEditorPlunginManager, Line 167.

Still, the form api documentation says its only for details and fieldsets...

tstoeckler’s picture

Interesting about CKEditorPlunginManager I wasn't aware of that. Ok, let's got with that then, since we have a precedent?!

dawehner’s picture

@dawehner: So that means you (also) prefer to go back to the patch in #24?

+1

k4v’s picture

I just re-tested #24 and it does not work, the elements are not added to the group.

Either I did some stupid mistake back then or something changed by now.

Could someone in charge of the form api look into this? I don't really understand how the #group, #parents and #optional are meant to work.

k4v’s picture

Another try at Drupalcon Barcelona =). After discussing this again with tstoeckler, he proposed this solution.

Status: Needs review » Needs work

The last submitted patch, 48: hide_empty_details-2409639-48.patch, failed testing.

k4v’s picture

fix this

k4v’s picture

Status: Needs work » Needs review

go testbot

Status: Needs review » Needs work

The last submitted patch, 50: hide_empty_details-2409639-49.patch, failed testing.

k4v’s picture

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 53: hide_empty_details-2409639-53.patch, failed testing.

The last submitted patch, 53: hide_empty_details-2409639-53.patch, failed testing.

k4v’s picture

k4v’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 57: hide_empty_details-2409639-57.patch, failed testing.

The last submitted patch, 57: hide_empty_details-2409639-57.patch, failed testing.

madhavvyas’s picture

+++ b/core/modules/views/src/Plugin/views/ViewsPluginInterface.php
--- a/core/modules/views/src/Plugin/views/argument/ManyToOne.php
+++ b/core/modules/views/src/Plugin/views/argument/ManyToOne.php

+++ b/core/modules/views/src/Plugin/views/argument/ManyToOne.php
@@ -72,7 +72,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
       '#description' => $this->t('If selected, users can enter multiple values in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'),

+++ b/core/modules/views/src/Plugin/views/argument/StringArgument.php
@@ -141,7 +141,7 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
+      '#group' => 'options][more',

+++ b/core/modules/views/src/Plugin/views/filter/FilterPluginBase.php
--- a/core/modules/views/src/Plugin/views/sort/SortPluginBase.php
+++ b/core/modules/views/src/Plugin/views/sort/SortPluginBase.php

Not sure about what is the use of "option][more" means? Please explain its significance

madhavvyas’s picture

Status: Needs work » Needs review
FileSize
23.52 KB

Fixed some coding standard issues

Status: Needs review » Needs work

The last submitted patch, 62: hide_empty_details-2409639-62.patch, failed testing.

The last submitted patch, 62: hide_empty_details-2409639-62.patch, failed testing.

k4v’s picture

@madhavvyas: we need "#group" => "options][more' because this is the mechanic of the #group property. It has to contain the complete path to the root of the form, with the strange '][' as separators.

I tried to throw out #fieldset entirely, but the tests fail because there are still other places that use #fieldset.

Not sure if we can change them all to use #group.

tstoeckler’s picture

Ahh @k4v nice catch!!! Very right you are. So let's just remove those hunks that remove the '#fieldset' functionality and just keep everything related to the 'more' stuff here. That should get us to a green patch. Then we can discuss removing the '#fieldset' stuff in a follow-up, but I fear that's D9 material at this point.

madhavvyas’s picture

Status: Needs work » Needs review
FileSize
583.91 KB

Sorry for that, I have reverted 'options][more' change as per patch provided by @k4v in comment #57

madhavvyas’s picture

FileSize
23.64 KB

Please dis-regards my last patch file it has some extra change due to rebase. Updating original Patch with 'options][more' changes.

The last submitted patch, 67: hide_empty_details-2409639-66.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 68: hide_empty_details-2409639-67.patch, failed testing.

k4v’s picture

@madhayvvas: thanks =).

I put the fieldset-code back in.

k4v’s picture

k4v’s picture

Status: Needs work » Needs review
tstoeckler’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Plugin/Block/ViewsBlockBase.php
    @@ -186,8 +186,8 @@ public function blockSubmit($form, FormStateInterface $form_state) {
    -   *   renderable array, containing the optional '#contextual_links' property (if
    ...
    +   *   render-able array, containing the optional '#contextual_links' property
    
  2. +++ b/core/modules/views/src/Plugin/views/argument/NumericArgument.php
    @@ -89,6 +89,8 @@ function title() {
    +   *
    +
    

The coding style changes introduced in #62 and following are a bit distracting in general, but some of the instances like the ones shown above a simply incorrect, so I don't think the patch can go in like this. Can we have a patch that's more like #57, but with all the #fieldset stuff reinstanted?

k4v’s picture

Status: Needs work » Needs review
FileSize
7.86 KB

new patch without the code style changes.

The last submitted patch, 67: hide_empty_details-2409639-66.patch, failed testing.

The last submitted patch, 68: hide_empty_details-2409639-67.patch, failed testing.

tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs issue summary update

Thanks a lot, verified again that this fixes the problem

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 75: hide_empty_details-2409639-75.patch, failed testing.

Status: Needs work » Needs review
k4v’s picture

Status: Needs review » Reviewed & tested by the community

not sure what happened here, putting it back to RTBC, the test is still green.

dawehner’s picture

As said, we need some tests.

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
k4v’s picture

This test should be red here, I include it in the following patch to show its green then.

k4v’s picture

This should be green. Yay.

k4v’s picture

Status: Needs work » Needs review

The last submitted patch, 84: assert_more_is_absent.patch, failed testing.

The last submitted patch, 84: assert_more_is_absent.patch, failed testing.

k4v’s picture

Issue tags: +Barcelona2015
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 85: hide_empty_details-2409639-85.patch, failed testing.

Status: Needs work » Needs review
madhavvyas’s picture

Looks good to me too!

k4v’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs review

There is still plenty of use of #fieldset in views...

Use the details elements the right way, possibly remove all the #fieldset logic from the views module.

We either need an issue summary update or more change. Which feels risky given the where we are at in the release cycle and benefits of this change.

k4v’s picture

Issue summary: View changes
tstoeckler’s picture

Status: Needs review » Reviewed & tested by the community

Yes, the updated issue summary makes it clear that this is only a bug fix and no API change is involved. We went that route with earlier patches, but no more.

alexpott’s picture

Issue tags: +Needs screenshots

Some before and after screenshots of the UI would be nice.

tstoeckler’s picture

Issue summary: View changes
Issue tags: -Needs screenshots
FileSize
30.48 KB
30.71 KB
30.47 KB

Here we go.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 458f5be and pushed to 8.0.x. Thanks!

Thanls for the screenshots and issue summary update.

  • alexpott committed 458f5be on 8.0.x
    Issue #2409639 by k4v, madhavvyas, katzilla, tstoeckler, hexabinaer,...
katzilla’s picture

Yeah - finally! Great work @all :-)

dawehner’s picture

yeah!!

k4v’s picture

Followup to possibly remove #fieldset everywhere: https://www.drupal.org/node/2581255

Status: Fixed » Closed (fixed)

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

The last submitted patch, 48: hide_empty_details-2409639-48.patch, failed testing.