eternalistic
8/30/2013 - 10:39 PM

Drupal 7 - Node preprocess

Drupal 7 - Node preprocess

/**
 * Override or insert variables into the node templates.
 *
 * @param $vars
 *   An array of variables to pass to the theme template.
 */
function THEMENAME_preprocess_node(&$vars) {

  $node = $vars['node'];

  // Custom submitted text
  switch ($vars['view_mode']) {
    case 'full':
      $vars['submitted'] = t('By') . ' ' . t('!username', array('!username' => $vars['name'])) . ' ' . t('on') . ' ' . '<time datetime=22-01-2011 pubdate>' . format_date($vars['node']->created, 'custom', 'F j, Y') . '</time>';
      
      break;

    case 'teaser':
      $vars['submitted'] = '<time datetime=22-01-2011 pubdate>' . format_date($vars['node']->created, 'custom', 'F j, Y') . '</time>';
      
      break;
  }

  switch ($node->type) {
    case 'article':

      switch ($vars['view_mode']) {
        //case 'teaser':
        case 'teaser_featured':

          // Add read more to body suffix
          $vars['content']['body']['#suffix'] = l(t('Read more') . ' &raquo;', 'node/' . $node->nid, array('html' => TRUE, 'attributes' => array('class' => 'readmore')));
          $vars['content']['field_featured_image']['#weight'] = '10';

      break;
    }
  }
}