You are here

public function LanguageBlock::build in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock::build()
  2. 9 core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock::build()

File

core/modules/language/src/Plugin/Block/LanguageBlock.php, line 84

Class

LanguageBlock
Provides a 'Language switcher' block.

Namespace

Drupal\language\Plugin\Block

Code

public function build() {
  $build = [];
  $route_name = $this->pathMatcher
    ->isFrontPage() ? '<front>' : '<current>';
  $type = $this
    ->getDerivativeId();
  $links = $this->languageManager
    ->getLanguageSwitchLinks($type, Url::fromRoute($route_name));
  if (isset($links->links)) {
    $build = [
      '#theme' => 'links__language_block',
      '#links' => $links->links,
      '#attributes' => [
        'class' => [
          "language-switcher-{$links->method_id}",
        ],
      ],
      '#set_active_class' => TRUE,
    ];
  }
  return $build;
}