Processes variables for node.tpl.php.
Most themes utilize their own copy of node.tpl.php. The default is located inside "modules/node/node.tpl.php". Look in there for the full list of variables.
$variables: An associative array containing:
function template_preprocess_node(&$variables) {
$variables['view_mode'] = $variables['elements']['#view_mode'];
// Provide a distinct $teaser boolean.
$variables['teaser'] = $variables['view_mode'] == 'teaser';
$variables['node'] = $variables['elements']['#node'];
$node = $variables['node'];
$variables['date'] = format_date($node->created);
$variables['name'] = theme('username', array(
'account' => $node,
'link_attributes' => array(
'rel' => 'author',
),
));
$uri = $node
->uri();
$variables['node_url'] = url($uri['path'], $uri['options']);
$variables['label'] = check_plain($node
->label());
$variables['page'] = $variables['view_mode'] == 'full' && node_is_page($node);
// Make useful flags and node data available.
// @todo: The comment properties only exist if comment.module is enabled, but
// are documented in node.tpl.php, so we make sure that they are set.
// Consider removing them.
$properties = array(
'type',
'comment_count',
'uid',
'created',
'promote',
'sticky',
'status',
'comment',
);
foreach ($properties as $property) {
$variables[$property] = isset($node->{$property}) ? $node->{$property} : NULL;
}
// Helpful $content variable for templates.
$variables += array(
'content' => array(),
);
foreach (element_children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
// Make the field variables available with the appropriate language.
field_attach_preprocess('node', $node, $variables['content'], $variables);
// Display post information only on certain node types.
if (variable_get('node_submitted_' . $node->type, TRUE)) {
$variables['display_submitted'] = TRUE;
$variables['submitted'] = t('Submitted by !username on !datetime', array(
'!username' => $variables['name'],
'!datetime' => $variables['date'],
));
if (theme_get_setting('toggle_node_user_picture')) {
// To change user picture settings (e.g. image style), edit the 'compact'
// view mode on User entity.
$variables['user_picture'] = user_view($node->account, 'compact');
}
else {
$variables['user_picture'] = array();
}
}
else {
$variables['display_submitted'] = FALSE;
$variables['submitted'] = '';
$variables['user_picture'] = '';
}
// Add article ARIA role.
$variables['attributes']['role'] = 'article';
// Gather node classes.
$variables['attributes']['class'][] = drupal_html_class('node-' . $node->type);
if ($node->promote) {
$variables['attributes']['class'][] = 'promoted';
}
if ($node->sticky) {
$variables['attributes']['class'][] = 'sticky';
}
if (!$node->status) {
$variables['attributes']['class'][] = 'unpublished';
}
if ($variables['view_mode']) {
$variables['attributes']['class'][] = drupal_html_class('view-mode-' . $variables['view_mode']);
}
if (isset($variables['preview'])) {
$variables['attributes']['class'][] = 'preview';
}
// Clean up name so there are no underscores.
$variables['theme_hook_suggestions'][] = 'node__' . $node->type;
$variables['theme_hook_suggestions'][] = 'node__' . $node->nid;
}