2

Where I can find drupal 8 language switcher block and/or theme file ?

I have been looking quite many blogs and forums for this but I either have not the files or not such code in file(s) they suggest. Thought there is modules like switcher dropdown but I would like to do just few changes my self to the code rather than using whole module which maybe fixes things I would like to :)

I wan't to add flag instead of link. However, another viable solution is to create own module and replace this language switcher module with it ?

Diamonte
  • 393
  • 7
  • 22

2 Answers2

2

Use twig debugging. The links.html.twig file control the language switcher block links. You can create links--language-block.html.twig and change the links in the template file.

Ann
  • 264
  • 1
  • 9
1

Have a look at core/modules/language/src/Plugin/Block/LanguageBlock.php

  /**
   * {@inheritdoc}
   */
  public function build() {
    $build = array();
    $route_name = $this->pathMatcher->isFrontPage() ? '<front>' : '<current>';
    $type = $this->getDerivativeId();
    $links = $this->languageManager->getLanguageSwitchLinks($type, Url::fromRoute($route_name));

    if (isset($links->links)) {
      $build = array(
        '#theme' => 'links__language_block',
        '#links' => $links->links,
        '#attributes' => array(
          'class' => array(
            "language-switcher-{$links->method_id}",
          ),
        ),
        '#set_active_class' => TRUE,
      );
    }
    return $build;
  }
leymannx
  • 5,138
  • 5
  • 45
  • 48