I wanted to change my theme's watermark to say "Scheduled" rather than "Unpublished", so I added this to Scheduler; I hope you'd like to use it.

/**
 * Implements hook_preprocess_node();
 * Makes the publish_on and unpublish_on data available as theme variables.
 */
function scheduler_preprocess_node(&$variables, $hook) {
  $node = $variables['node'];
  $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT);
  if (isset($node->publish_on)) {
    $variables['publish_on'] = date($date_format, $node->publish_on);
  }
  if (isset($node->unpublish_on)) {
    $variables['unpublish_on'] = date($date_format, $node->unpublish_on);
  }
}

Sorry, I didn't check out Scheduler so making a patch is a pain. This is strictly added code that I put at the very end of the module.

Comments

NancyDru’s picture

For those who want to change the theme with this:

    <?php if ($unpublished): ?>
      <div class="unpublished"><?php print $publish_on ? t('Scheduled') : t('Unpublished'); ?></div>
    <?php endif; ?>
Eric-Alexander Schaefer’s picture

This is actually a really great idea. It could also be used in the theme for having a different coloring for unpublished but scheduled nodes.

NancyDru’s picture

Sure could. Many themes have an unpublished watermark, so I just extended mine (based on Zen) to have a scheduled watermark. But, yes, you could also assign a "scheduled" class to the node so that the CSS could assign a different color, or borders, etc.

NancyDru’s picture

Small change required for node preview.

/**
* Implements hook_preprocess_node();
* Makes the publish_on and unpublish_on data available as theme variables.
*/
function scheduler_preprocess_node(&$variables, $hook) {
  $node = $variables['node'];
  $date_format = variable_get('scheduler_date_format', SCHEDULER_DATE_FORMAT);
  if (!empty($node->publish_on)) {
    $variables['publish_on'] = date($date_format, $node->publish_on);
  }
  if (!empty($node->unpublish_on)) {
    $variables['unpublish_on'] = date($date_format, $node->unpublish_on);
  }
}
Eric-Alexander Schaefer’s picture

There is a fix for that over there: #893260: date() expects parameter 2 to be long, string given

(oh, you were faster with that... ;-)

NancyDru’s picture

Yes, this includes that fix.

Since this is new code that can be placed anywhere, I haven't done a proper patch. It works fine for me on a high-volume site.

Eric-Alexander Schaefer’s picture

Just thinking: format_date() might be a better choice over date()...

Eric-Alexander Schaefer’s picture

Title: Theme variabes » Theme variables
Status: Active » Needs review
NancyDru’s picture

Status: Needs review » Fixed

Works for me. The format_date is more translation-friendly. I just copied code you had elsewhere, so you might want to look over your other code.

Status: Fixed » Closed (fixed)

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