"Who's new" & "Who's online" blocks in D8

<div id="block-user-new" class="block block-user" role="complementary">

    <h2>Who's new</h2>
  
  <div class="content">
    <div class="item-list"><h3></h3><ul><li class="odd first last"><span class="username" lang="" about="/user/1" typeof="sioc:UserAccount" property="foaf:name">openconcept</span></li></ul></div>  </div>
</div>

And when logged on:

<p>There is currently 1 user online.</p><div class="item-list"><h3></h3><ul><li class="odd first last"><span class="username" lang="" about="/user/1" typeof="sioc:UserAccount" property="foaf:name">openconcept</span></li></ul></div> </div>

Never should headings be empty.

Comments

joachim’s picture

The failure is in theme_item_list():

    if ($title !== '') {
      $title = '<h3>' . $title . '</h3>';
    }

This lets through a $title of NULL. Anyone with a better grasp of PHP's empty/null/isset malarkey care to tackle this? :)

Everett Zufelt’s picture

Assuming that we never want an unset, NULL, or '' / 0 / '0' (empty) $title, we should use:

if (!empty($title)) { ... }

Assuming that we want to allow '0' or 0, we want:

// $title is set, is not NULL, and is not the empty string ''.
if (isset($title) && $title !== '') { ... }

Assuming that we want to allow '0', but not 0 (which evaluates to the empty string '')

// $title is set, is not NULL, and does not evaluate to the empty string ''.
if (isset($title) && $title != '') { ... }

My guess is that we want the third example.

Everett Zufelt’s picture

Hmmm,

I'm wrong, '0' evaluates to '' too.

webchick’s picture

Heh, read it and weep. :) http://php.net/manual/en/types.comparisons.php <3 PHP

Everett Zufelt’s picture

Status: Active » Needs review
StatusFileSize
new493 bytes

Bottom line, do we want $title = '0' or 0 to be printed as 0, or ignored?

The attached patch will print $title if it does not evaluate to the empty string. So, $title will not be printed if $title=='0'. I think we can live with that here, I don't believe that we have a Coding Standard for rendering empty strings.

mgifford’s picture

#5: theme_item_list-empty_title.patch queued for re-testing.

BrockBoland’s picture

Can anyone explain how to replicate this condition? I would test the patch, but I can't get it to NOT work in the first place.

mgifford’s picture

Have you got Drupal 8 up with the What's New block enabled?

Where are you stuck?

BrockBoland’s picture

mgifford: I've got a site running the 8.x HEAD and added both blocks to the sidebar. Both as an admin and anonymous user, I'm seeing the title on both blocks. I tried overriding the block titles to 0 or empty string, and it worked as expected (no h2 tags) in both cases.

joachim’s picture

> Bottom line, do we want $title = '0' or 0 to be printed as 0, or ignored?

I suspect that if we don't allow a block title consisting of a single '0', someone down the line will file a bug because that's what they need...

mgifford’s picture

StatusFileSize
new443.05 KB
new446.87 KB

Here's a screenshot of HEAD before & after the patch is applied. Includes both the WAVE Toolbar report as well as the source. Try downloading http://wave.webaim.org/toolbar and running it against your system. You should see the same images.

I think this is ready to RTBC. Just it's hard to see if you don't know what to look for.

kgoel’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new315.77 KB
new270.19 KB

Reproduced the problem and got two empty heading errors (accessibility errors). Applied the patch and Voila! got no errors. Please see screenshots after patch was applied. I think it can be marked as RTBC.

I have been doing some accessibility work so picked this patch to test.

mgifford’s picture

Thanks @kgoel. Do let us know if you'd like to be part of our monthly accessibility discussions announced http://groups.drupal.org/accessibility

kgoel’s picture

Sure @mgifford. Please let me know if in anyway I can help out.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Sorry I'm confused, 0 should not be equivalent to '' with a strict comparison, which is what the existing code has. So why can't we just check for isset and the strict check as suggested in #5?

// $title is set, is not NULL, and is not the empty string ''.
if (isset($title) && $title !== '') { ... }

Regardless, there should be a code comment explaining the accessibility issue.

kgoel’s picture

Based on Catch's comment #15. In this patch checking to see if title is set and its not null and empty string. Also added accessibility comment.

kgoel’s picture

StatusFileSize
new755 bytes

Trying again with the right patch.

xjm’s picture

Status: Needs work » Needs review

Thanks @kgoel! Setting NR for the bot to test it.

mgifford’s picture

Think the description could be clearer:

// Check to see If the block $title exists before creating the block heading.
// Empty headers are bad form and present accessibility challenges.

The bot needs to test the code though.

kgoel’s picture

StatusFileSize
new668 bytes

updated description :)

xjm’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new665 bytes

Ah, I think that is better comment text. Thanks @mgifford and @kgoel!

Attached cleans up the comment a bit more. RTBCing nonetheless because the changes from #20 are trivial.

catch’s picture

Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs backport to D7

Thanks! Committed/pushed to 8.x.

This should probably be backported.

kgoel’s picture

StatusFileSize
new646 bytes

D7 patch

kgoel’s picture

Status: Patch (to be ported) » Needs review

Status: Needs review » Needs work

The last submitted patch, 1349722-23.patch, failed testing.

kgoel’s picture

Version: 8.x-dev » 7.x-dev

Changed version in the issue from 8.x to 7.x for backport.

Everett Zufelt’s picture

Status: Needs work » Needs review
Everett Zufelt’s picture

#23: 1349722-23.patch queued for re-testing.

kgoel’s picture

StatusFileSize
new652 bytes

Fixed the commenting indenting. Updated patch for D7

xjm’s picture

Status: Needs review » Needs work

Thanks @kgoel. The backport looks pretty good but needs one small change:

+++ b/includes/theme.incundefined
@@ -1967,8 +1967,11 @@ function theme_item_list($variables) {
+// Only output the list container and title, if there are any list items.
+// Check to see whether the block title exists before adding a header.
+// Empty headers are not semantic and present accessibility challenges.

These comments should be indented by two spaces.

kgoel’s picture

StatusFileSize
new658 bytes

Thanks xjm! Learning something with each patch. Updated one for D7

kgoel’s picture

Status: Needs work » Needs review
xjm’s picture

That was fast! Setting "Needs review" so it will be tested. :)

xjm’s picture

Status: Needs review » Reviewed & tested by the community

Oh whoops, looks like I was posting at the same time as you! The indentation in #29 is correct--I was referring to the earlier version. :)

So RTBC for #29 (not #31).

kgoel’s picture

Thanks xjm!

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed #29 to 7.x. Thanks!

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