You are here

class LanguageBlock in Drupal 9

Same name in this branch
  1. 9 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock
  2. 9 core/modules/language/src/Plugin/Block/LanguageBlock.php \Drupal\language\Plugin\Block\LanguageBlock
Same name and namespace in other branches
  1. 8 core/modules/language/src/Plugin/Derivative/LanguageBlock.php \Drupal\language\Plugin\Derivative\LanguageBlock

Provides language switcher block plugin definitions for all languages.

Hierarchy

Expanded class hierarchy of LanguageBlock

File

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

Namespace

Drupal\language\Plugin\Derivative
View source
class LanguageBlock extends DeriverBase {

  /**
   * {@inheritdoc}
   */
  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)', [
          '@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);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
LanguageBlock::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions