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.
| Comment | File | Size | Author |
|---|---|---|---|
| #62 | interdiff_1645328_51-62-simple.txt | 2.11 KB | andregp |
| #62 | 1645328-62-simple-test.patch | 1.74 KB | andregp |
| #53 | hacky_test.png | 78.46 KB | andregp |
| #51 | 1645328-51.patch | 1.99 KB | darvanen |
| #36 | drupal-theme_fieldset_title_isset-1645328-36-D8.patch | 4.65 KB | liam morland |
Comments
Comment #1
liam morlandReroll.
Comment #2
liam morlandReroll.
Comment #4
liam morland#2: drupal_theme_fieldset_title_isset.patch queued for re-testing.
Comment #5
liam morlandReroll.
Comment #6
sunThe 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.
Comment #7
liam morlandRegarding 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.Comment #8
mandar.harkare commentedComment #9
mandar.harkare commentedComment #10
sunSorry for the late reply.
The comparison operator has to be strict (!==), because otherwise a title of "0" would not be appear.
Comment #11
liam morlandI 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.
Comment #12
mandar.harkare commentedI 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.
Comment #13
liam morlandFALSE 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.
Comment #14
liam morlandReroll.
Comment #15
liam morlandComment #16
liam morland#2152209: Convert theme_fieldset() to Twig is held up. Can we get this committed first?
Comment #17
liam morlandReroll.
Comment #18
liam morlandComment #19
liam morlandComment #20
jhedstromPatch no longer applies.
Comment #21
liam morlandComment #22
jhedstromThe 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 inDrupal\system\Tests\Form\ElementTest.Comment #23
liam morlandVersion with test. I also had to adjust the twig template to make it work the way it is supposed to.
Comment #24
idebr commentedAccording 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?
Comment #25
shravan sonkar commentedComment #26
shravan sonkar commentedComment #27
shravan sonkar commentedComment #29
David Hernández commentedHello!
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 #.
Comment #30
manningpete commentedPatch applies.
Comment #31
jhedstromTrailing whitespace issues.
When fixing those, could the test also be attached separately to illustrate the current failing behavior?
Comment #32
liam morlandUpdated patch and test-only patch attached.
Comment #34
liam morlandThe patch that failed is supposed to fail.
Comment #35
jhedstromPatch in #32 makes sense to me. Can somebody address the concerns in #24?
Comment #36
liam morlandHere 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.
Comment #48
darvanenTriaging as part of the Bug Smash Initiative.
Looks to me like
template_preprocess_fieldsetdoesn't useempty()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.
Comment #49
liam morlandIf this has been fixed then the tests from the patch could be added and they ought to pass.
Comment #50
darvanenGood point!
Having trouble locally, let's see what the testbot makes of this.
Comment #51
darvanenOops, missed actually adding the test elements.
Comment #52
liam morlandThis failure shows that the problem has not been fixed. A
fieldset legendof "0" (zero) does not appear.Comment #53
andregp commentedThat'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).
Comment #54
liam morlandIt's not a complicated test. Does the thing you are seeing match the XPath in the test?
Comment #55
andregp commentedLooking 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.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-fieldsetlooks like.Comment #56
andregp commentedSomehow, 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.Comment #57
liam morlandA
fieldsetis not required to have alegend. It shouldn't generate an emptylegend.Comment #58
andregp commented@Liam Morland
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
legendtags. Should we report this on a new issue?Comment #59
liam morlandYes, this issue is about allowing any string value. Removing empty would be a separate issue.
Comment #60
andregp commentedOkay, so what I understood so far is:
1. We shouldn't rely on checking the contents of
legendas 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 thelegendtag.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?
Comment #61
liam morlandThe title field should still be displayed if the title is zero. If it is doing so, this should be tested for.
Comment #62
andregp commentedSo here is a patch with a very simple test that shows the title is correctly displayed when the
#titleis equal to 0I 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 emptyComment #63
liam morlandTest passes and tests for what the issue title is about. Thanks
Comment #65
andregp commentedRadom unrelated fail, restoring status
Comment #66
alexpottFixing the title.
Comment #67
alexpottThis was fixed in #2192419: Use a WCAG-compliant fieldset (fieldgroup) for #type radios/checkboxes.
Comment #68
alexpottCommitted 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.