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();
    $route_name = $this-&gt;pathMatcher-&gt;isFrontPage() ? '&lt;front&gt;' : '&lt;current&gt;';
    $type = $this-&gt;getDerivativeId();
    $links = $this-&gt;languageManager-&gt;getLanguageSwitchLinks($type, Url::fromRoute($route_name));

    if (isset($links-&gt;links)) {
      $build = array(
        '#theme' =&gt; 'links__language_block',
        '#links' =&gt; $links-&gt;links,
        '#attributes' =&gt; array(
          'class' =&gt; array(
            "language-switcher-{$links-&gt;method_id}",
          ),
        ),
        '#set_active_class' =&gt; TRUE,
      );
    }
    return $build;
  }
I finally found what the problem was.
This code "$type = $this-&gt;getDerivativeId();" was null, and, as a result, this code "$links = $this-&gt;languageManager-&gt;getLanguageSwitchLinks($type, Url::fromRoute($route_name));" could not build the following part of the $links array:

"[language] =&gt; Drupal\language\Entity\ConfigurableLanguage Object
                    (
                        [id:protected] =&gt; en
                        [label:protected] =&gt; English
                        [direction:protected] =&gt; ltr
                        [weight:protected] =&gt; -10
                        [locked:protected] =&gt; 
                        [preSaveMultilingual:protected] =&gt; 
                        [originalId:protected] =&gt; en
                        [status:protected] =&gt; 1
                        [uuid:protected] =&gt; 6c14f789-dcf3-4149-883f-63c29df3e544
                        [isSyncing:Drupal\Core\Config\Entity\ConfigEntityBase:private] =&gt; 
                        [isUninstalling:Drupal\Core\Config\Entity\ConfigEntityBase:private] =&gt; 
                        [langcode:protected] =&gt; en
                        [third_party_settings:protected] =&gt; Array
                            (
                            )

                        [_core:protected] =&gt; Array
                            (
                                [default_config_hash] =&gt; HolYKYAaiuzaHd7bV6FOM0HVbmmEMd3Zq4JAcgW55_4
                            )

                        [trustedData:protected] =&gt; 
                        [entityTypeId:protected] =&gt; configurable_language
                        [enforceIsNew:protected] =&gt; 
                        [typedData:protected] =&gt; 
                        [cacheContexts:protected] =&gt; Array
                            (
                                [0] =&gt; languages:language_interface
                                [1] =&gt; url.site
                            )

                        [cacheTags:protected] =&gt; Array
                            (
                            )

                        [cacheMaxAge:protected] =&gt; -1
                        [_serviceIds:protected] =&gt; Array
                            (
                            )

                        [dependencies:protected] =&gt; Array
                            (
                            )

                    )"


All the above was missing, so the url could not be properly build.
The solution was to add "Derivative" php file for my class, just like the core language module includes both the "core/modules/language/src/Plugin/Block/LanguageBlock.php" and the "core/modules/language/src/Plugin/Derivative/LanguageBlock.php".
Of course, you have to fix the machine names and namespaces if you do something similar.