theme.inc in Node displays 6
Theming functions for nd.
File
theme/theme.incView source
<?php
/**
* @file
* Theming functions for nd.
*/
/**
* Theme function to render the field content.
*
* @param string $content The content to render.
* @param string $field_key The name of the field key.
* @param array $field The current field.
*/
function theme_nd_field($content, $field_key, $field) {
$output = '';
if (!empty($content)) {
if ($field['type'] == 'nd') {
$output .= '<div class="field field-' . $field_key . '">';
// Above label.
if ($field['labelformat'] == 'above') {
$output .= '<div class="field-label">' . $field['title'] . ': </div>';
}
// Inline label
if ($field['labelformat'] == 'inline') {
$output .= '<div class="field-label-inline-first">' . $field['title'] . ': </div>';
}
$output .= $content;
$output .= '</div>';
}
else {
$output = $content;
}
}
return $output;
}
/**
* Template helper for theme_views_view_row_node
*/
function template_preprocess_nd_row_node(&$vars) {
$options = $vars['options'];
$vars['node'] = '';
// make sure var is defined.
$nid = $vars['row']->nid;
if (!is_numeric($nid)) {
return;
}
$node = node_load($nid);
$node->build_mode = $options['build_mode'];
if (empty($node)) {
return;
}
$teaser = $node->build_mode != 'full' ? TRUE : FALSE;
$vars['node'] = node_view($node, $teaser, FALSE, $options['show_links']);
}
/**
* Theme preprocess function for nd-display-overview-form.tpl.php.
*
* We are overriding the complete theming function to add
* weights and regions which will be saved automatically in the display settings.
*/
function template_preprocess_nd_display_overview_form(&$vars) {
$form =& $vars['form'];
$build_mode = $form['#build_mode'];
// Order the fields.
$order = array();
foreach ($form['#fields'] as $key => $field) {
$order[$field] = $form[$field]['nd_weight']['#default_value'];
}
asort($order);
// Render exclude build mode checkbox.
$vars['exclude_build_mode'] = drupal_render($form['exclude_build_mode']);
$rows = array();
foreach ($order as $key => $field) {
$element =& $form[$key];
$row = new stdClass();
// Each field will have a region, store it temporarily
$region = $element[$build_mode]['region']['#default_value'];
foreach (element_children($element) as $child) {
// Render the display fields
if ($child == $build_mode) {
$row->{$child}->label = drupal_render($element[$child]['label']);
$row->{$child}->format = drupal_render($element[$child]['format']);
$row->{$child}->region = drupal_render($element[$child]['region']);
}
else {
// Process weight.
if ($child == 'nd_weight') {
$element['nd_weight']['#attributes']['class'] = 'field-weight field-weight-' . $region;
$element['nd_weight'] = process_weight($element['nd_weight']);
}
$row->{$child} = drupal_render($element[$child]);
}
}
// Add draggable.
$row->class = 'draggable';
if ($region == 'disabled') {
$row->class .= ' region-css-' . $region;
}
$row->label_class = 'label-field';
$rows[$region][] = $row;
}
drupal_add_js('misc/tableheader.js');
drupal_add_js(drupal_get_path('module', 'nd') . '/js/nd.js');
drupal_add_css(drupal_get_path('module', 'nd') . '/css/nd.css');
$regions = nd_regions($build_mode);
foreach ($regions as $region => $title) {
drupal_add_tabledrag('fields', 'match', 'sibling', 'field-region-select', 'field-region-' . $region, NULL, FALSE);
// We need to have subgroups to make the dragging available within parents
drupal_add_tabledrag('fields', 'order', 'sibling', 'field-weight', 'field-weight-' . $region);
}
// Plugins available.
if (isset($form['#plugins'])) {
$vars['plugins'] = TRUE;
$vars['plugins_content'] = '';
foreach ($form['#plugin_keys'] as $key) {
$vars['plugins_content'] .= drupal_render($form[$key]);
}
}
$vars['submit'] = drupal_render($form);
$vars['regions'] = $regions;
$vars['rows'] = $rows;
$vars['build_mode'] = $build_mode;
$vars['extra_style'] = $form['exclude_build_mode']['#default_value'] == TRUE ? 'style="display: none;"' : '';
}
/**
* Fields.
*/
function theme_nd_bodyfield(&$node) {
$node->body_rendered = $node->content['body']['#value'];
}
function theme_nd_title_h1_nolink(&$node) {
$node->title_rendered = '<h1>' . check_plain($node->title) . '</h1>';
}
function theme_nd_title_h1_link(&$node) {
$node->title_rendered = '<h1>' . l($node->title, 'node/' . $node->nid) . '</h1>';
}
function theme_nd_title_h2_nolink(&$node) {
$node->title_rendered = '<h2>' . check_plain($node->title) . '</h2>';
}
function theme_nd_title_h2_link(&$node) {
$node->title_rendered = '<h2>' . l($node->title, 'node/' . $node->nid) . '</h2>';
}
function theme_nd_title_h2_block_nolink(&$node) {
$node->title_rendered = '<h2 class="block-title">' . check_plain($node->title) . '</h2>';
}
function theme_nd_title_h2_block_link(&$node) {
$node->title_rendered = '<h2 class="block-title">' . l($node->title, 'node/' . $node->nid) . '</h2>';
}
function theme_nd_title_p_nolink(&$node) {
$node->title_rendered = '<p>' . check_plain($node->title) . '</p>';
}
function theme_nd_title_p_link(&$node) {
$node->title_rendered = '<p>' . l($node->title, 'node/' . $node->nid) . '</p>';
}
function theme_nd_author_link(&$node) {
$node->author_rendered = theme('username', $node);
}
function theme_nd_author_nolink(&$node) {
$node->author_rendered = $node->name;
}
Functions
Name | Description |
---|---|
template_preprocess_nd_display_overview_form | Theme preprocess function for nd-display-overview-form.tpl.php. |
template_preprocess_nd_row_node | Template helper for theme_views_view_row_node |
theme_nd_author_link | |
theme_nd_author_nolink | |
theme_nd_bodyfield | Fields. |
theme_nd_field | Theme function to render the field content. |
theme_nd_title_h1_link | |
theme_nd_title_h1_nolink | |
theme_nd_title_h2_block_link | |
theme_nd_title_h2_block_nolink | |
theme_nd_title_h2_link | |
theme_nd_title_h2_nolink | |
theme_nd_title_p_link | |
theme_nd_title_p_nolink |