You are here

function workspace_preprocess_workspace_rev in Workspace 8

Prepares variables for revision templates.

File

./workspace.module, line 162

Code

function workspace_preprocess_workspace_rev(&$variables) {
  $uuid = $variables['elements']['#uuid'];
  $rev = $variables['elements']['#rev'];
  $rev_info = array_merge(\Drupal::service('multiversion.entity_index.rev')
    ->get("{$uuid}:{$rev}"), $variables['elements']['#rev_info']);
  $variables = array_merge($variables, $rev_info);
  list($i) = explode('-', $rev);

  // Apart from the index length, we want 7 characters plus dash and ellipsis.
  $length = strlen($i) + 9;
  $title = Unicode::truncate($rev, $length, FALSE, TRUE);
  if (!empty($rev_info['revision_id'])) {
    $entity_revision = \Drupal::entityTypeManager()
      ->getStorage($rev_info['entity_type_id'])
      ->loadRevision($rev_info['revision_id']);
    $variables['title'] = Link::fromTextAndUrl($title, $entity_revision
      ->toUrl('revision'));
  }
  else {
    $variables['title'] = $title;
  }
}