You are here

function theme_revisioning_revisions_summary in Revisioning 8

Same name and namespace in other branches
  1. 6.4 revisioning_theme.inc \theme_revisioning_revisions_summary()
  2. 6.3 revisioning_theme.inc \theme_revisioning_revisions_summary()
  3. 7 revisioning_theme.inc \theme_revisioning_revisions_summary()

Theme revision summary table.

Theme the supplied form as a table, then prepend submenu links via revisions-summary.tpl.php

Uses the following subthemes: o 'table_revisions', falling back to theme.inc/theme_table() if not defined o 'placeholder' (to display current revision status) o 'username' Uses the following style-classes (see revisioning.css) o 'table-revisions' o 'revision-current' and 'published' o 'revision-pending'

Parameters

array $variables: The variables array

Return value

string The rendered html

File

./revisioning_theme.inc, line 198
Include file for revisioning.module; deals with all theming aspects.

Code

function theme_revisioning_revisions_summary($variables) {
  $form = $variables['form'];
  if (!isset($form['nid'])) {
    drupal_set_message(t('theme_revisioning_revisions_summary(): form does not contain nid - aborting.'), 'error');
    return;
  }

  // Need node info, fortunately node_load() employs a cache so is efficient.
  $node = node_load($form['nid']['#value']);
  drupal_add_css(drupal_get_path('module', 'revisioning') . '/revisioning.css');

  // Set up the table rows.
  $rows = array();
  $revision_ids = element_children($form['info']);
  $show_diff = count($revision_ids) >= 2 && module_exists('diff');

  // Set up the table header.
  $header = array(
    t('Revision'),
  );
  if ($show_diff) {
    $header[] = array(
      'data' => drupal_render($form['submit']),
      'class' => 'form-submit',
    );
  }
  if (isset($form['tags'])) {
    $header[] = t('Tags');
  }
  if (isset($form['term'])) {
    $header[] = t('Terms');
  }
  $header[] = t('Status');
  $is_initial_unpublished_draft = !$node->status && count($revision_ids) == 1;

  // From the $form columns create table $rows.
  foreach ($revision_ids as $vid) {
    $row = array();

    // Column #1: Revision info.
    $row[] = drupal_render($form['info'][$vid]);

    // Column #2: Compare checkbox.
    if ($show_diff) {
      $row[] = array(
        'data' => drupal_render($form['tickbox'][$vid]),
      );
    }

    // Columns #3 & #4: Tags & Terms.
    if (isset($form['tags'])) {
      $row[] = filter_xss(drupal_render($form['tags'][$vid]));
    }
    if (isset($form['term'])) {
      $row[] = filter_xss(drupal_render($form['term'][$vid]));
    }

    // Column #4: Publication status.
    $is_current = $vid == $node->vid;
    $is_pending = $vid > $node->vid || $is_initial_unpublished_draft;
    if ($is_pending) {
      $status = array(
        'data' => t('in draft/pending publication'),
      );
    }
    else {
      $status = array(
        'data' => $is_current && $node->status ? drupal_placeholder(t('current revision (published)')) : t('archived'),
      );
    }
    $row[] = $status;

    // Apply CSS class.
    $row_style = $is_current ? array(
      'revision-current',
    ) : ($is_pending ? array(
      'revision-pending',
    ) : array());
    if ($is_current && $node->status == NODE_PUBLISHED) {
      $row_style[] = 'published';
    }
    $rows[] = array(
      'data' => $row,
      'class' => $row_style,
    );
  }

  // Render $header and $rows as a table.
  $table_variables = array(
    'header' => $header,
    'rows' => $rows,
    'attributes' => array(
      'class' => array(
        'table-revisions',
      ),
    ),
  );
  $content = theme(array(
    'table_revisions',
    'table',
  ), $table_variables);

  // Prepend submenu links.
  $submenu_links = _revisioning_generate_node_links_according_to_permissions($node);

  // Combine submenu links and rendered table using a template (.tpl.php) file.
  $template_variables = array(
    'submenu_links' => $submenu_links,
    'content' => $content,
  );
  $output = theme(array(
    'revisions_summary',
  ), $template_variables);
  return $output . drupal_render_children($form);
}