You are here

public function LanguageBlock::getDerivativeDefinitions in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock::getDerivativeDefinitions()

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

core/modules/language/src/Plugin/Derivative/LanguageBlock.php, line 21
Contains \Drupal\language\Plugin\Derivative\LanguageBlock.

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'] = t('Language switcher (@type)', array(
        '@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'] = t('Language switcher');
    }
  }
  return parent::getDerivativeDefinitions($base_plugin_definition);
}