function BlockHooks::pageTop

Implements hook_page_top().

Attributes

#[Hook('page_top')]

File

core/modules/block/src/Hook/BlockHooks.php, line 123

Class

BlockHooks
Hook implementations for block.

Namespace

Drupal\block\Hook

Code

public function pageTop(array &$page_top) : void {
  if (\Drupal::routeMatch()->getRouteName() === 'block.admin_demo') {
    $theme = \Drupal::theme()->getActiveTheme()
      ->getName();
    $page_top['backlink'] = [
      '#type' => 'link',
      '#title' => $this->t('Exit block region demonstration'),
      '#options' => [
        'attributes' => [
          'class' => [
            'block-demo-backlink',
          ],
        ],
      ],
      '#weight' => -10,
    ];
    if (\Drupal::config('system.theme')->get('default') == $theme) {
      $page_top['backlink']['#url'] = Url::fromRoute('block.admin_display');
    }
    else {
      $page_top['backlink']['#url'] = Url::fromRoute('block.admin_display_theme', [
        'theme' => $theme,
      ]);
    }
  }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.