You are here

protected function ModerationSidebarController::getBackButton in Moderation Sidebar 8

Generates the render array for an AJAX-enabled back button.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: An entity.

Return value

array A render array representing a back button.

2 calls to ModerationSidebarController::getBackButton()
ModerationSidebarController::revisionOverview in src/Controller/ModerationSidebarController.php
Generates an simple list of revisions for a node.
ModerationSidebarController::translateOverview in src/Controller/ModerationSidebarController.php
Generate a simple list of translations with quick-add buttons.

File

src/Controller/ModerationSidebarController.php, line 647

Class

ModerationSidebarController
Endpoints for the Moderation Sidebar module.

Namespace

Drupal\moderation_sidebar\Controller

Code

protected function getBackButton(ContentEntityInterface $entity) {
  $params = [
    'entity' => $entity
      ->id(),
    'entity_type' => $entity
      ->getEntityTypeId(),
  ];
  if (\Drupal::request()
    ->get('latest')) {
    $back_url = Url::fromRoute('moderation_sidebar.sidebar_latest', $params);
  }
  else {
    $back_url = Url::fromRoute('moderation_sidebar.sidebar', $params);
  }
  $build = [
    '#type' => 'container',
    '#attributes' => [
      'class' => [
        'moderation-sidebar-container',
      ],
    ],
    [
      '#title' => $this
        ->t('← Back'),
      '#type' => 'link',
      '#url' => $back_url,
      '#attributes' => [
        'class' => [
          'use-ajax',
          'moderation-sidebar-back-button',
        ],
        'data-dialog-type' => 'dialog',
        'data-dialog-renderer' => 'off_canvas',
      ],
    ],
  ];
  return $build;
}