You are here

function bean_revisions_page in Bean (for Drupal 7) 7

Revisions page callback

Parameters

$bean Bean:

1 string reference to 'bean_revisions_page'
bean_menu in ./bean.module
Implements hook_menu().

File

includes/bean.pages.inc, line 649
Bean Functions

Code

function bean_revisions_page(Bean $bean) {
  $bean
    ->loadRevisions();

  // Build the sortable table header.
  $header = array(
    'vid' => array(
      'data' => t('Revision ID'),
    ),
    'title' => array(
      'data' => t('Title'),
    ),
    'author' => array(
      'data' => t('Author'),
    ),
    'changed' => array(
      'data' => t('Date Changed'),
    ),
    'operations' => array(
      'data' => t('Operations'),
      'colspan' => 2,
    ),
  );
  $rows = array();

  // Dont' show link for default revision
  $can_delete = entity_access('delete', 'bean', $bean);
  $can_edit = entity_access('update', 'bean', $bean);
  foreach ($bean->revisions as $rev) {
    $active = $rev->vid == $bean->vid ? TRUE : FALSE;
    $user = user_load($rev->uid);
    $rows[$rev->vid] = array(
      'vid' => $active ? t('@label (Current Revision)', array(
        '@label' => $rev->vid,
      )) : $rev->vid,
      'title' => array(
        'data' => array(
          '#type' => 'link',
          '#title' => $rev->label,
          '#href' => "block/{$rev->delta}/revisions/{$rev->vid}",
        ),
      ),
      'author' => format_username($user),
      'changed' => format_date($rev->changed),
    );
    $operations = array();
    if ($can_edit) {
      $operations['edit'] = array(
        'title' => t('edit'),
        'href' => "block/{$bean->delta}/revisions/{$rev->vid}/edit",
        'query' => drupal_get_destination(),
      );
    }
    if ($can_delete && !$active) {
      $operations['delete'] = array(
        'title' => t('delete'),
        'href' => "block/{$bean->delta}/revisions/{$rev->vid}/delete",
        'query' => drupal_get_destination(),
      );
    }
    if ($can_edit && !$active) {
      $operations['set-active'] = array(
        'title' => t('set active'),
        'href' => "block/{$bean->delta}/revisions/{$rev->vid}/set-active",
        'query' => drupal_get_destination(),
      );
    }
    $rows[$rev->vid]['operations'] = array(
      'data' => array(
        '#theme' => 'links__bean_operations',
        '#links' => $operations,
        '#attributes' => array(
          'class' => array(
            'links',
            'inline',
          ),
        ),
      ),
    );
  }
  return array(
    '#theme' => 'table',
    '#header' => $header,
    '#rows' => $rows,
    '#empty' => t('There are no revisions'),
  );
}