You are here

function taxonomy_revision_taxonomy_revisions in Taxonomy revision 7

Function which return a more complex form when diff module is activated.

_state

Parameters

$form:

$viewed_term:

Return value

mixed

1 string reference to 'taxonomy_revision_taxonomy_revisions'
taxonomy_revision_overview in ./taxonomy_revision.pages.inc
Generate an overview table of older revisions of a taxonomy term.

File

./taxonomy_revision.pages.inc, line 450
UI pages for revisions, similar with pages from node.pages.inc.

Code

function taxonomy_revision_taxonomy_revisions($form, $form_state, $viewed_term) {
  drupal_set_title(t('Revisions for %title', array(
    '%title' => $viewed_term->name,
  )), PASS_THROUGH);
  $form['nid'] = array(
    '#type' => 'hidden',
    '#value' => $viewed_term->revision_id,
  );
  $revision_list = taxonomy_revision_list($viewed_term);
  if (count($revision_list) > REVISION_LIST_SIZE) {

    // If the list of revisions is longer than the number shown on one page
    // split the array.
    $page = isset($_GET['page']) ? $_GET['page'] : '0';
    $revision_chunks = array_chunk(taxonomy_revision_list($viewed_term), REVISION_LIST_SIZE);
    $revisions = $revision_chunks[$page];

    // Set up global pager variables as would 'pager_query' do.
    // These variables are then used in the theme('pager') call later.
    global $pager_page_array, $pager_total, $pager_total_items;
    $pager_total_items[0] = count($revision_list);
    $pager_total[0] = ceil(count($revision_list) / REVISION_LIST_SIZE);
    $pager_page_array[0] = max(0, min($page, (int) $pager_total[0] - 1));
  }
  else {
    $revisions = $revision_list;
  }
  $delete_permission = FALSE;
  $revert_permission = FALSE;
  if (user_access('revert taxonomy term revisions') || user_access('administer taxonomy')) {
    $revert_permission = TRUE;
  }
  if (user_access('delete taxonomy term revisions') || user_access('administer taxonomy')) {
    $delete_permission = TRUE;
  }

  // Take all of the revisions.
  foreach ($revisions as $revision) {
    $operations = array();
    $revision_ids[$revision->revision_id] = '';
    $revision_log = $revision->log != '' ? '<p class="revision-log">' . filter_xss($revision->log) . '</p>' : '';
    if ($revision->current_revision_id > 0) {
      $form['info'][$revision->revision_id] = array(
        '#markup' => t('!date by !username', array(
          '!date' => l(format_date($revision->timestamp, 'small'), "taxonomy/term/{$viewed_term->tid}"),
          '!username' => theme('username', array(
            'account' => $revision,
          )),
        )) . $revision_log,
      );
    }
    else {
      $diff_date = l(format_date($revision->timestamp, 'small'), "taxonomy/term/{$viewed_term->tid}/revisions/{$revision->revision_id}/view");
      $form['info'][$revision->revision_id] = array(
        '#markup' => t('!date by !username', array(
          '!date' => $diff_date,
          '!username' => theme('username', array(
            'account' => $revision,
          )),
        )) . $revision_log,
      );
      if ($revert_permission) {
        $operations[] = array(
          '#markup' => l(t('Revert'), "taxonomy/term/{$viewed_term->tid}/revisions/{$revision->revision_id}/revert"),
        );
      }
      if ($delete_permission) {
        $operations[] = array(
          '#markup' => l(t('Delete'), "taxonomy/term/{$viewed_term->tid}/revisions/{$revision->revision_id}/delete"),
        );
      }

      // Set a dummy, even if the user has no permission for the other
      // operations, so that we can check if the operations array is
      // empty to know if the row denotes the current revision.
      $operations[] = array();
    }
    $form['operations'][$revision->revision_id] = $operations;
  }
  $new_vid = key($revision_ids);
  next($revision_ids);
  $old_vid = key($revision_ids);
  $form['diff']['old'] = array(
    '#type' => 'radios',
    '#options' => $revision_ids,
    '#default_value' => $old_vid,
  );
  $form['diff']['new'] = array(
    '#type' => 'radios',
    '#options' => $revision_ids,
    '#default_value' => $new_vid,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Compare'),
  );
  if (count($revision_list) > REVISION_LIST_SIZE) {
    $form['#suffix'] = theme('pager');
  }
  $attachments['css'] = array(
    drupal_get_path('module', 'diff') . "/css/diff.default.css",
  );
  $attachments['js'] = array(
    drupal_get_path('module', 'diff') . "/js/diff.js",
    array(
      'data' => array(
        'diffRevisionRadios' => 'simple',
      ),
      'type' => 'setting',
    ),
  );
  $form['#attached'] = $attachments;
  return $form;
}