function LanguageBlock::getDerivativeDefinitions

Same name in other branches
  1. 8.9.x core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock::getDerivativeDefinitions()
  2. 10 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock::getDerivativeDefinitions()
  3. 11.x core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock::getDerivativeDefinitions()

Overrides DeriverBase::getDerivativeDefinitions

File

core/modules/language/src/Plugin/Derivative/LanguageBlock.php, line 19

Class

LanguageBlock
Provides language switcher block plugin definitions for all languages.

Namespace

Drupal\language\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
    $language_manager = \Drupal::languageManager();
    if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
        $info = $language_manager->getDefinedLanguageTypesInfo();
        $configurable_types = $language_manager->getLanguageTypes();
        foreach ($configurable_types as $type) {
            $this->derivatives[$type] = $base_plugin_definition;
            $this->derivatives[$type]['admin_label'] = $this->t('Language switcher (@type)', [
                '@type' => $info[$type]['name'],
            ]);
        }
        // If there is just one configurable type then change the title of the
        // block.
        if (count($configurable_types) == 1) {
            $this->derivatives[reset($configurable_types)]['admin_label'] = $this->t('Language switcher');
        }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.