It's not possible to customize the $submitted variable in Zen subthemes, because the MYTHEME_preprocess_node function is called *before* zen_preprocess_node, so any changes to $submitted made by the sub-theme template are overriden by zen_preprocess_node. This would affect also to _preprocess_page and _preprocess_comment.

The solution would be either altering the call order of _preprocess_node hooks (right now I don't know if that can be done), or detecting whether $submitted has been altered by the subtheme template (which looks difficult).

Related issues:
http://drupal.org/node/987916
http://drupal.org/node/364470

Comments

star-szr’s picture

Category: bug » support
Status: Active » Postponed (maintainer needs more info)

I can't reproduce this - can you please post your MYTHEME_preprocess_node() code if you're still having this issue?

John Franklin’s picture

Status: Postponed (maintainer needs more info) » Active

I'm seeing the same thing, using Zen 7.x-5.1. My THEME_preprocess_node() is about as simple as it gets:

<?php
function mytheme_preprocess_node(&$variables, $hook) {

  if ($variables['display_submitted']) {
    $variables['submitted'] = t('By !username, !datetime', array('!username' => $variables['name'], '!datetime' => format_date($variables['node']->created, 'byline')));
  }
  
  // Optionally, run node-type-specific preprocess functions, like
  // kbr_preprocess_node_page() or kbr_preprocess_node_story().
//  $function = __FUNCTION__ . '_' . $variables['node']->type;
//  if (function_exists($function)) {
//    $function($variables, $hook);
//  }
}
?>

dpm() calls (not shown) in this function and in zen_preprocess_node() confirm the calling order.

John Franklin’s picture

Nevermind. I'm an idiot. This site has a site-specific theme and a site specific module, both named the same thing. The version of _preprocess_node named for the module is winning out over the theme. Renaming one or the other fixes it.

echoz’s picture

Assigned: albertczyk » Unassigned
Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

albertczyk’s picture

Version: 7.x-5.x-dev » 7.x-5.4
Assigned: Unassigned » albertczyk
Category: Support request » Bug report
Issue summary: View changes
Status: Closed (fixed) » Active

I had forgot about this issue until it reappeared again... Now I'm back with an example:

mysubtheme/template.php:

function MYSUBTHEME_preprocess_node_petition(&$variables, $hook) {
   global $language;
   $lang = LANGUAGE_NONE;

   setlocale(LC_TIME, 'es_ES');
   $author = user_load($variables['uid']);

   if ( isset($author->picture) )
      $author_picture = 
         image_style_url('square_thumbnail', $author->picture->uri);
   else
      $author_picture = '/'.path_to_theme().'/images/go.png';

   $variables['submitted'] = '<img class="author-picture" src="'.$author_picture.'">' .
      t('By !name &middot; !city, !country &middot; !time', 
         array( 
            '!uid' => $variables['uid'], 
            '!name' => $variables['name'], 
            '!city' => $author->field_city[$lang][0]['value'],
            '!country' => $author->field_country[$lang][0]['value'],
            '!time' => strftime('%e %h %Y', $variables['created'])
         )
      );
}

zen/template.php:


function zen_preprocess_node(&$variables, $hook) {
  // Add $unpublished variable.
  $variables['unpublished'] = (!$variables['status']) ? TRUE : FALSE;

  // Add pubdate to submitted variable.
  $variables['pubdate'] = '<time pubdate datetime="' . format_date($variables['node']->created, 'custom', 'c') . '">' . $variables['date'] . '</time>';
  if ($variables['display_submitted']) {
    $variables['submitted'] = t('Submitted by !username on !datetime', array('!username' => $variables['name'], '!datetime' => $variables['pubdate']));
  }

(....)

If I comment out the line that sets $variables['submitted'] in zen_preprocess_node(), my $submitted shows up. If I don't, then my $submitted is overriden.

The clean solution would be to guarantee that zen_preprocess_node is executed before all preprocess_node hooks in the active subtheme. If there is no way to achieve this, then probably it would be wise to check if the variables are already set before overwriting them.

albertczyk’s picture

For what I'm seeing, there is no easy solution, as the theme has no control over the hook calling sequence, so there is no way to block the subtheme's hooks from being called before the main zen hooks - unless your hook function is alphabetically after zen_preprocess_node

JohnAlbin’s picture

Version: 7.x-5.4 » 7.x-5.x-dev
Assigned: albertczyk » Unassigned

I'm not sure a fix is possible.

JohnAlbin’s picture

Title: Not possible to customize $submitted variable » Not possible to customize $submitted variable in preprocess
Category: Bug report » Support request
Status: Active » Fixed

But you can make the change in a THEME_process_HOOK() function.

Status: Fixed » Closed (fixed)

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