You are here

function revisioning_revisions_summary in Revisioning 7

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. 6.3 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

array $form: typically an empty array as passed in by drupal_get_form()

array $form_state: the form state

int $extra: parameters as passed into drupal_get_form(), see _theme_revisions_summary()

Return value

array updated form containing all data to be themed

4 string references to 'revisioning_revisions_summary'
revisioning_scheduler_form_alter in revisioning_scheduler/revisioning_scheduler.module
Implements hook_form_alter().
revisioning_ux_form_alter in revisioning_ux/revisioning_ux.module
Implements hook_form_alter().
revisioning_ux_page_alter in revisioning_ux/revisioning_ux.module
Implements hook_page_alter().
_revisioning_theme_revisions_summary in ./revisioning_theme.inc
Theme the revisions summary of the supplied node.

File

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

Code

function revisioning_revisions_summary($form, &$form_state, $extra) {

  // #type=>'value' form field values will not appear in the HTML. Used here
  // to pass the node id to theme_revisioning_revisions_summary().
  // Or: $form_state['build_info']['args'][0]; ?
  $nid = $extra;
  $form['nid'] = array(
    '#type' => 'value',
    '#value' => $nid,
  );
  $show_taxonomy_terms = module_exists('taxonomy') && variable_get('revisioning_show_taxonomy_terms', TRUE) && count(taxonomy_get_vocabularies()) > 0;
  $revisions = _revisioning_get_all_revisions_for_node($nid, $show_taxonomy_terms);
  $revision_ids = array();
  $published = FALSE;
  foreach ($revisions as $revision) {
    $vid = $revision->vid;
    if ($vid == $revision->current) {
      $title = $revision->title;
      $published = $revision->status;
    }

    // No text next to check boxes (see below).
    $revision_ids[$vid] = '';
    $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, 'short'), "{$base_url}/view"),
      '!username' => theme('username', array(
        'account' => $revision,
      )),
    )) . (empty($revision->log) ? '' : '<p class="revision-log">' . filter_xss($revision->log) . '</p>');
    $form['info'][$vid] = array(
      // Was: 'item', see [#1884696].
      '#type' => 'markup',
      '#markup' => $first_cell,
    );

    // Third & fourth columns: term (2nd column is handled below).
    if (!empty($revision->tags)) {
      $form['tags'][$vid] = array(
        '#type' => 'item',
        '#markup' => $revision->tags,
      );
      $has_tags = TRUE;
    }
    if (!empty($revision->term)) {
      $form['term'][$vid] = array(
        '#type' => 'item',
        '#markup' => $revision->term,
      );
      $has_terms = TRUE;
    }
    $form['status'][$vid] = array(
      '#type' => 'value',
      '#value' => $revision->status,
    );
  }

  // Close foreach ($revisions as $revision).
  if (empty($has_tags)) {
    unset($form['tags']);
  }
  if (empty($has_terms)) {
    unset($form['term']);
  }
  revisioning_set_status_message(format_plural(count($revisions), '%title is @publication_status. It has only one revision', '%title is @publication_status. It has @count revisions.', array(
    '%title' => $title,
    '@publication_status' => $published ? t('published') : t('NOT published'),
  )));
  if (count($revisions) >= 2 && module_exists('diff')) {

    // Second column: check-boxes to select two revisions to compare
    // The default selection is the top two check-boxes
    $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;
}