Create a fieldset with a title of zero. It will should appear. This was broken is Drupal 7 and was fixed in #2192419: Use a WCAG-compliant fieldset (fieldgroup) for #type radios/checkboxes.

This issue will add test coverage that was not added when this fixed in 2192419.

Comments

liam morland’s picture

StatusFileSize
new934 bytes

Reroll.

liam morland’s picture

StatusFileSize
new1015 bytes

Reroll.

Status: Needs review » Needs work

The last submitted patch, drupal_theme_fieldset_title_isset.patch, failed testing.

liam morland’s picture

Status: Needs work » Needs review
liam morland’s picture

Issue summary: View changes
StatusFileSize
new1.03 KB

Reroll.

sun’s picture

Status: Needs review » Needs work

The type-casts are unnecessary and should be removed. But aside from that, the proposed change makes sense to me.

This patch will need a re-roll after #2152209: Convert theme_fieldset() to Twig has landed.

liam morland’s picture

Regarding typecasts, would you prefer removing them and using != instead of !==? That doesn't bother me, though the cast is happening internally anyway, so it might as well be explicit.

mandar.harkare’s picture

StatusFileSize
new755 bytes
mandar.harkare’s picture

Status: Needs work » Needs review
sun’s picture

Status: Needs review » Needs work

Sorry for the late reply.

The comparison operator has to be strict (!==), because otherwise a title of "0" would not be appear.

liam morland’s picture

I use the cast with strict comparison because I want to be sure that any non-empty string value will be accepted and anything that casts to an empty string will not be accepted. Someone could set the title to FALSE, for example. That casts to empty, so it would not get get. int 0 casts to sting 0, so that would generate the header as it should.

mandar.harkare’s picture

I agree with Liam here. If someone set the title to FALSE, it would not get in. What needs to be identified is what would it do ideally if someone set title to FALSE, should it get in or not, I think it should.

liam morland’s picture

FALSE casts to the empty string, so it would not generate a legend or description div. I think that would be the expected behavior. In any case, it would be wrong to generate an empty legend or description div, so my patch ensures that that does not happen.

liam morland’s picture

StatusFileSize
new1.22 KB

Reroll.

liam morland’s picture

Status: Needs work » Needs review
liam morland’s picture

#2152209: Convert theme_fieldset() to Twig is held up. Can we get this committed first?

liam morland’s picture

Reroll.

liam morland’s picture

liam morland’s picture

jhedstrom’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Patch no longer applies.

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new1.09 KB
jhedstrom’s picture

The fix in #19 makes sense, and I agree leaving the type casting in place makes sense.

@Liam would you feel comfortable adding a test for this so it doesn't regress in the future? I think this would go in Drupal\form_test\Form\FormTestGroupFieldsetForm, and then ensure the expected markup in Drupal\system\Tests\Form\ElementTest.

liam morland’s picture

Version with test. I also had to adjust the twig template to make it work the way it is supposed to.

idebr’s picture

According to the Twig documentation an empty should evaluate to false, see http://twig.sensiolabs.org/doc/tags/if.html

Or does Drupal implement a different version of Twig if that I am not aware of?

The rules to determine if an expression is true or false are the same as in PHP; here are the edge cases rules:

Value Boolean evaluation
empty string false
numeric zero false
whitespace-only string true
empty array false
null false
non-empty array true
object true
shravan sonkar’s picture

Issue tags: +#SprintWeekend2015
StatusFileSize
new4.96 KB
shravan sonkar’s picture

shravan sonkar’s picture

The last submitted patch, 25: drupal-theme_fieldset_title_isset-1645328-25.patch, failed testing.

David Hernández’s picture

Issue tags: -#SprintWeekend2015 +SprintWeekend2015

Hello!

Thank you for working on this issue!

We should all try and use the same sprint tag. According to https://groups.drupal.org/node/447258 it should be SprintWeekend2015 with no #.

manningpete’s picture

Issue tags: -Needs reroll

Patch applies.

jhedstrom’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/src/Tests/Form/ElementTest.php
@@ -129,6 +129,19 @@ function testGroupElements() {
+    ¶
...
+    ¶

Trailing whitespace issues.

When fixing those, could the test also be attached separately to illustrate the current failing behavior?

liam morland’s picture

Status: Needs work » Needs review
StatusFileSize
new4.95 KB
new1.39 KB

Updated patch and test-only patch attached.

Status: Needs review » Needs work

The last submitted patch, 32: drupal-theme_fieldset_title_test_only-1645328-32-D8.patch, failed testing.

liam morland’s picture

Status: Needs work » Needs review

The patch that failed is supposed to fail.

jhedstrom’s picture

Patch in #32 makes sense to me. Can somebody address the concerns in #24?

liam morland’s picture

Here is a patch without the " != ''". Given what was in #24, this should behave the same way as the previous patch since the values being compared are always strings.

Status: Needs review » Needs work

The last submitted patch, 36: drupal-theme_fieldset_title_isset-1645328-36-D8.patch, failed testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
darvanen’s picture

Status: Needs work » Postponed (maintainer needs more info)
Issue tags: +Bug Smash Initiative, +Needs steps to reproduce, +Needs issue summary update

Triaging as part of the Bug Smash Initiative.

Looks to me like template_preprocess_fieldset doesn't use empty() any more, and the lack of activity here for many years would indicate that it's no longer an issue.

But just in case, instead of closing this I'm tagging it for issue summary update and steps to reproduce and marking it PMNMI. If there is no further activity after 3 months this issue may be closed.

liam morland’s picture

Issue summary: View changes
Status: Postponed (maintainer needs more info) » Active
Issue tags: -Needs steps to reproduce, -Needs issue summary update

If this has been fixed then the tests from the patch could be added and they ought to pass.

darvanen’s picture

Version: 9.3.x-dev » 9.4.x-dev
StatusFileSize
new1.16 KB

Good point!

Having trouble locally, let's see what the testbot makes of this.

darvanen’s picture

StatusFileSize
new1.99 KB

Oops, missed actually adding the test elements.

liam morland’s picture

Status: Active » Needs work

This failure shows that the problem has not been fixed. A fieldset legend of "0" (zero) does not appear.

andregp’s picture

StatusFileSize
new78.46 KB

That's weird... A simple (and hacky) manual test shows that the title is actually visible, what does not appear is the description (which makes me suspect that maybe the test isn't right).

liam morland’s picture

It's not a complicated test. Does the thing you are seeing match the XPath in the test?

andregp’s picture

StatusFileSize
new141.47 KB

Looking deeper I noticed that the problem is just the page where the asserts are happening. They should be moved up a a few lines so they are executed after the $this->drupalGet('form-test/group-fieldset'); like this.

public function testGroupElements() {
  $this->drupalGet('form-test/group-details');
  $this->assertSession()->elementsCount('xpath', '//div[@class="details-wrapper"]//div[@class="details-wrapper"]//label', 1);
  $this->drupalGet('form-test/group-container');
  $this->assertSession()->elementsCount('xpath', '//div[@id="edit-container"]//div[@class="details-wrapper"]//label', 1);
  $this->drupalGet('form-test/group-fieldset');
  $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset"]//div[@id="edit-meta"]//label', 1);

  $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset-zero"]//legend', 1);
  //$this->assertNotEmpty($this->cssSelect('#edit-fieldset-zero>legend>span')[0]);
  $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset-zero"]//div[@id="edit-fieldset-zero--description"]', 1);
  $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset-false"]//legend', 1);
  //$this->assertEmpty($this->cssSelect('#edit-fieldset-false>legend>span')[0]);
  $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset-false"]//div[@id="edit-fieldset-false--description"]', 0);

  $this->drupalGet('form-test/group-vertical-tabs');
  $this->assertSession()->elementsCount('xpath', '//div[@data-vertical-tabs-panes]//details[@id="edit-meta"]//label', 1);
  $this->assertSession()->elementsCount('xpath', '//div[@data-vertical-tabs-panes]//details[@id="edit-meta-2"]//label', 1);
}

Another problem I noticed is that the html actually creates a legend element, even when there's no title inside, so instead of counting for 0 elements we should check if the content is empty (that's what I tried to do on the above commented out lines of code, but I had no success).

I'm attaching a file of how the html from form-test/group-fieldset looks like.

andregp’s picture

Somehow, all my attempts to check the text inside span (either using xpath() or cssSelector()) failed. These functions return an array of \Behat\Mink\Element\NodeElement[]. If I try to access the first element and use the getValue() method from NodeElement (like $this->cssSelect('#edit-fieldset-false>legend>zero')[0]->getValue() for example) it always return NULL for me.

liam morland’s picture

A fieldset is not required to have a legend. It shouldn't generate an empty legend.

andregp’s picture

@Liam Morland

It shouldn't generate an empty legend

This is weird. I got the code at html_test.png (#55) by using a var_dump() on the test and it generated the empty legend tags. Should we report this on a new issue?

liam morland’s picture

Yes, this issue is about allowing any string value. Removing empty would be a separate issue.

andregp’s picture

Okay, so what I understood so far is:
1. We shouldn't rely on checking the contents of legend as a way to prove that the title isn't showing because this tag shouldn't appear at all when there's no title. This means we either keep the $this->assertSession()->elementsCount('xpath', '//fieldset[@id="edit-fieldset-false"]//legend', 0); and postpone this issue here until the legend problem is fixed, or we find another way to test that doesn't rely on the legend tag.
2. We should probably update the issue summary to focus on fixing the description field instead of the title field (as the title is apparently working as per #53)

Is it right?

liam morland’s picture

The title field should still be displayed if the title is zero. If it is doing so, this should be tested for.

andregp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.74 KB
new2.11 KB

So here is a patch with a very simple test that shows the title is correctly displayed when the #title is equal to 0
I also created a new issue to deal with the <legend> element appearing even when the title is empty: #3283883: Fieldset should not create title element when title is empty

liam morland’s picture

Status: Needs review » Reviewed & tested by the community

Test passes and tests for what the issue title is about. Thanks

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 62: 1645328-62-simple-test.patch, failed testing. View results

andregp’s picture

Status: Needs work » Reviewed & tested by the community

Radom unrelated fail, restoring status

alexpott’s picture

Title: theme_fieldset() should allow any non-empty-string #title » Add test to ensure fieldset allows any non-empty-string #title
Category: Bug report » Task

Fixing the title.

alexpott’s picture

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed 8915191bae to 10.0.x and 42bbd1ad1d to 9.5.x and 4465497ee8 to 9.4.x. Thanks!

Backported this to 9.4.x as it is a test-only patch.

  • alexpott committed 8915191 on 10.0.x
    Issue #1645328 by Liam Morland, darvanen, shravan sonkar, andregp,...

  • alexpott committed 42bbd1a on 9.5.x
    Issue #1645328 by Liam Morland, darvanen, shravan sonkar, andregp,...

  • alexpott committed 4465497 on 9.4.x
    Issue #1645328 by Liam Morland, darvanen, shravan sonkar, andregp,...

Status: Fixed » Closed (fixed)

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