The USWDS base theme does not currently include any default styling for unpublished nodes (node-unpublished class) or unpublished comments (comment-unpublished class). It would be useful if the USWDS base theme included some simple styles out of the box to visually notify site users when the items they are viewing aren't published. A simple background color change could be a good place to start.

For 508 compliance a conditional div containing the word unpublished run through the t function in supplied node.tpl.php and comment.tpl.php files could be even more useful. What are your thoughts @brockfanning? I am happy to supply a patch for this.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

JayDarnell created an issue. See original summary.

JayDarnell’s picture

Attached is a potential patch to add some basic styling for unpublished comments and unpublished nodes as well as a small conditional mark tag with t('unpublished') contained inside.

The changes include:

  • A small addition to the styles.css file
  • A new slightly modified copy of the core node.tpl.php file
  • A new slightly modified copy of the core comments.tpl.php file
  • A new node.preprocess.inc file
brockfanning’s picture

Thanks @JayDarnell, I think this definitely needs doing. My only hesitation is because I'm wondering if it can be done without overriding the templates. If so, it seems like that would be preferable, since it would work whether or not any subthemes may have overridden a node/comment template.

I know the class can be added without overriding the template, but I'm not sure about how the tag would be done.

JayDarnell’s picture

Hi @brockfanning, good point. I modeled this update after what the Zen base theme does and after reading some discussions here on D.O about how to do something similar in D8.

The way I see I it, for new projects using USWDS moving forward the unpublished tag will already be in place in the provided comment and node templates. I'm not sure if we would need to note this anywhere in the project documentation so site builders looking to use the base theme know to clone the templates provided by USWDS instead of those provided by core. It couldn't hurt but I imagine most themers may already know to check the base them for templates to override...

For other projects already in the wild this shouldn't have any negative impact if they're already running their own custom comment and node templates right? We already had our own on the LINCS project for example and adding this to the base theme had no negative impact on us. In these cases site builders will get the benefit of the background color styling for the unpublished items but they won't get the additional mark tag unless they decide to copy that snippet into their own template.

Truth be told, I came up empty handed trying to think of a better way to do this.

brockfanning’s picture

Status: Active » Needs work

That makes sense, Jay. Here are some comments on the patch:

  1. +++ b/css/style.css
    @@ -233,3 +233,7 @@ fieldset.form-wrapper legend {
    +.node.node-unpublished,
    +.comment.comment-unpublished {
    +  background-color: #fff4f4;
    +}
    

    A nitpick, but in the interest of CSS selector simplicity, wouldn't it still work without the "node." and "comment."?

  2. +++ b/preprocess/node.preprocess.inc
    @@ -0,0 +1,13 @@
    +<?php
    +
    +/**
    + * @file
    + * Preprocess function for this hook.
    + */
    +
    +/**
    + * Implements hook_preprocess_node().
    + */
    +function uswds_preprocess_node(&$variables) {
    +  $variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE;
    +}
    

    Could we get by without this file, by consulting variables['status'] instead of variables['unpublished'] in the template?

  3. +++ b/templates/system/comment.tpl.php
    

    Technically shouldn't this be templates/comment/comment.tpl.php?

  4. +++ b/templates/system/comment.tpl.php
    @@ -0,0 +1,97 @@
    +    ¶
    +    <?php if ($status == 'comment-unpublished'): ?>
    +      <mark class="unpublished"><?php print t('Unpublished'); ?></mark>
    +    <?php endif; ?>
    +    ¶
    

    Possible whitespace issue.

  5. +++ b/templates/system/node.tpl.php
    

    Technically shouldn't this be templates/node/node.tpl.php?

  6. +++ b/templates/system/node.tpl.php
    @@ -0,0 +1,117 @@
    +    ¶
    +    <?php if ($unpublished): ?>
    +      <mark class="unpublished"><?php print t('Unpublished'); ?></mark>
    +    <?php endif; ?>
    +    ¶
    

    Possible whitespace issue.

brockfanning’s picture

Forgot to add, if possible can you add a little doc above the CSS lines, like /* Help for admins */?

JayDarnell’s picture

Hi @brockfanning. Thanks for the feedback. I'll rework and submit a fresh patch as soon as possible.

JayDarnell’s picture

Hello again @brockfanning. I didn't exactly follow your comments regarding possible white space issues but I've rerolled the patch with the rest of your recommendations.

brockfanning’s picture

Looking good Jay. To elaborate on the whitespace issue - for example the line above <?php if (!$status): ?> has whitespace (four spaces), as does the line below that section. And similar for the comment template.

JayDarnell’s picture

Thanks for clarifying @brockfanning. I should be able to submit a follow-up patch sometime today.

JayDarnell’s picture

As promised here is an updated patch without the unnecessary white space.

brockfanning’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Assigned: JayDarnell » Unassigned
Status: Needs work » Needs review
FileSize
9.88 KB

Thanks @JayDarnell!

I'm attaching a hopefully equivalent D8 version of the patch for review.

  • brockfanning committed 8f1eec2 on 8.x-1.x
    Issue #2934688 by JayDarnell, brockfanning: Missing Unpublished State
    
brockfanning’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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