You are here

public function LanguageDropdownBlock::getDerivativeDefinitions in Language Switcher Dropdown 8.2

Gets the definition of all derivatives of a base plugin.

Parameters

array $base_plugin_definition: The definition array of the base plugin.

Return value

array An array of full derivative definitions keyed on derivative id.

Overrides DeriverBase::getDerivativeDefinitions

See also

getDerivativeDefinition()

File

src/Plugin/Derivative/LanguageDropdownBlock.php, line 48

Class

LanguageDropdownBlock
Provides dropdown switcher block plugin definitions for all languages.

Namespace

Drupal\lang_dropdown\Plugin\Derivative

Code

public function getDerivativeDefinitions($base_plugin_definition) {
  if ($this->languageManager instanceof ConfigurableLanguageManagerInterface) {
    $info = $this->languageManager
      ->getDefinedLanguageTypesInfo();
    $configurable_types = $this->languageManager
      ->getLanguageTypes();
    foreach ($configurable_types as $type) {
      $this->derivatives[$type] = $base_plugin_definition;
      $this->derivatives[$type]['admin_label'] = $this
        ->t('Language dropdown 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 dropdown switcher');
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}