Skip to main content
2 of 3
removed tags from title
avpaderno
  • 97.9k
  • 15
  • 164
  • 284

Custom language switcher block, returning urls problem

In Drupal 8, i am trying to create a custom language switcher block. So, I created a custom module, where I created a new class that extends the "LanguageBlock" class of the core language module. I utilize the build() method, that builds alright my custom block. The problem though, is that the resulting links of my custom block, return a pattern like this in the url:

  • http://base_url/?language_content_entity=en
  • http://base_url/?language_content_entity=de
  • http://base_url/?language_content_entity=es

and the language does not change, whereas the default language switcher block works fine. This problem occurs even if the build() method is copy/paste from the parent class, and/or even if I just return parent::build(), with no editing whatsoever. Does anybody have a clue why this is happening, and maybe a possible solution? Thank you.

PS: The code of the build() method.

public function build() {
    $build = array();

    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;
  }