You are here

function revisioning_revisions_summary in Revisioning 6.3

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

Return revisions summary table data. If the Diff modules is enabled, the object returned includes a column of checkboxes allowing the user to select two revisions for side-by-side comparison.

Parameters

$form_state:

$nid, the id of the node:

Return value

form containing all data to be themed

2 string references to 'revisioning_revisions_summary'
revisioning_scheduler_form_alter in revisioning_scheduler/revisioning_scheduler.module
Adds a text field and checkbox to the revisioning form. Implementation of hook_form_alter().
_theme_revisions_summary in ./revisioning_theme.inc
Theme the revisions summary of the supplied node.

File

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

Code

function revisioning_revisions_summary($form_state, $nid) {
  $form = array();

  // #type=>'value' form field values will not appear in the HTML. Used to pass
  // the node id to revisioning_revisions_summary_submit() and
  // theme_revisioning_revisions_summary().
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );
  $show_taxonomy_terms = module_exists('taxonomy') && count(taxonomy_get_vocabularies()) > 0 && variable_get("show_taxonomy_terms", TRUE);
  $revisions = _revisioning_get_all_revisions_for_node($nid, $show_taxonomy_terms);
  $revision_ids = array();
  foreach ($revisions as $revision) {
    if (!empty($revision->type)) {

      // This is the current revision, holding publication status and content type
      $content_type = $revision->type;
      $title = $revision->title;
      $published = $revision->status;
    }
    $vid = $revision->vid;
    $revision_ids[$vid] = '';

    // no text next to check box
    $base_url = "node/{$nid}/revisions/{$vid}";

    // First column: saved date + author
    $first_cell = t('Saved !date by !username', array(
      '!date' => l(format_date($revision->timestamp, 'small'), "{$base_url}/view"),
      '!username' => theme('username', $revision),
    )) . (empty($revision->log) ? '' : '<p class="revision-log">' . filter_xss($revision->log) . '</p>');
    $form['info'][$vid] = array(
      '#value' => $first_cell,
    );

    // Third column: term (2nd column is handled below)
    if ($show_taxonomy_terms) {
      $form['term'][$vid] = array(
        '#value' => $revision->term,
      );
    }
  }
  drupal_set_message(format_plural(count($revisions), '@publication_status @content_type %title has only one revision', '@publication_status @content_type %title has @count revisions.', array(
    '@publication_status' => $published ? t('Published') : t('Unpublished'),
    '@content_type' => $content_type,
    '%title' => $title,
  )));
  if (count($revisions) >= 2 && module_exists('diff')) {

    // Second column: check-boxes to select two revisions to compare
    $id1 = key($revision_ids);
    next($revision_ids);
    $id2 = key($revision_ids);
    $form['tickbox'] = array(
      '#type' => 'checkboxes',
      '#options' => $revision_ids,
      '#default_value' => array(
        $id1,
        $id2,
      ),
      '#required' => TRUE,
    );

    // Submit button
    $form['submit'] = array(
      '#value' => t('Compare'),
      '#type' => 'submit',
    );
  }
  return $form;
}