protected function PluginRevisionController::buildRevisionsNavigation in Diff 8
Creates navigation links between the previous changes and the new ones.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to be compared.
array $revision_ids: The revision ids.
int $left_revision_id: Revision id of the left revision.
int $right_revision_id: Revision id of the right revision.
string $filter: The filter.
Return value
array The revision navigation links.
1 call to PluginRevisionController::buildRevisionsNavigation()
- PluginRevisionController::compareEntityRevisions in src/
Controller/ PluginRevisionController.php - Returns a table which shows the differences between two entity revisions.
File
- src/
Controller/ PluginRevisionController.php, line 234
Class
- PluginRevisionController
- Base class for controllers that return responses on entity revision routes.
Namespace
Drupal\diff\ControllerCode
protected function buildRevisionsNavigation(ContentEntityInterface $entity, array $revision_ids, $left_revision_id, $right_revision_id, $filter) {
$revisions_count = count($revision_ids);
$layout_options =& drupal_static(__FUNCTION__);
if (!isset($layout_options)) {
$layout_options = UrlHelper::filterQueryParameters($this->requestStack
->getCurrentRequest()->query
->all(), [
'page',
]);
}
// If there are only 2 revision return an empty row.
if ($revisions_count == 2) {
return [];
}
else {
$left_link = $right_link = '';
$element = [
'#type' => 'item',
'#title' => $this
->t('Navigation'),
'#wrapper_attributes' => [
'class' => 'diff-navigation',
],
];
$i = 0;
// Find the previous revision.
while ($left_revision_id > $revision_ids[$i]) {
$i += 1;
}
if ($i != 0) {
// Build the left link.
$left_link = Link::fromTextAndUrl($this
->t('Previous change'), $this
->diffRoute($entity, $revision_ids[$i - 1], $left_revision_id, $filter, $layout_options))
->toString();
}
$element['left'] = [
'#type' => 'markup',
'#markup' => $left_link,
'#prefix' => '<div class="diff-navigation__link prev-link">',
'#suffix' => '</div>',
];
// Find the next revision.
$i = 0;
while ($i < $revisions_count && $right_revision_id >= $revision_ids[$i]) {
$i += 1;
}
if ($revisions_count != $i && $revision_ids[$i - 1] != $revision_ids[$revisions_count - 1]) {
// Build the right link.
$right_link = Link::fromTextAndUrl($this
->t('Next change'), $this
->diffRoute($entity, $right_revision_id, $revision_ids[$i], $filter, $layout_options))
->toString();
}
$element['right'] = [
'#type' => 'markup',
'#markup' => $right_link,
'#prefix' => '<div class="diff-navigation__link next-link">',
'#suffix' => '</div>',
];
return $element;
}
}