You are here

public function DomainSwitcherBlock::build in Domain Access 8

Build the output.

Overrides BlockPluginInterface::build

File

domain/src/Plugin/Block/DomainSwitcherBlock.php, line 29

Class

DomainSwitcherBlock
Provides a block that links to all domains.

Namespace

Drupal\domain\Plugin\Block

Code

public function build() {

  /** @var \Drupal\domain\DomainInterface $active_domain */
  $active_domain = \Drupal::service('domain.negotiator')
    ->getActiveDomain();
  $items = [];

  /** @var \Drupal\domain\DomainInterface $domain */
  foreach (\Drupal::entityTypeManager()
    ->getStorage('domain')
    ->loadMultipleSorted() as $domain) {
    $string = $domain
      ->getLink();
    if (!$domain
      ->status()) {
      $string .= '*';
    }
    if ($domain
      ->id() == $active_domain
      ->id()) {
      $string = '<em>' . $string . '</em>';
    }
    $items[] = [
      '#markup' => $string,
    ];
  }
  return [
    '#theme' => 'item_list',
    '#items' => $items,
  ];
}