class LanguageDropdownBlock in Language Switcher Dropdown 8.2
Same name in this branch
- 8.2 src/Plugin/Derivative/LanguageDropdownBlock.php \Drupal\lang_dropdown\Plugin\Derivative\LanguageDropdownBlock
- 8.2 src/Plugin/Block/LanguageDropdownBlock.php \Drupal\lang_dropdown\Plugin\Block\LanguageDropdownBlock
Provides dropdown switcher block plugin definitions for all languages.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\lang_dropdown\Plugin\Derivative\LanguageDropdownBlock implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of LanguageDropdownBlock
File
- src/
Plugin/ Derivative/ LanguageDropdownBlock.php, line 15
Namespace
Drupal\lang_dropdown\Plugin\DerivativeView source
class LanguageDropdownBlock extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The language manager service.
*
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
protected $languageManager;
/**
* Constructs new LanguageDropdownBlock.
*
* @param \Drupal\Core\Language\LanguageManagerInterface $language_manager
* The language manager service.
*/
public function __construct(LanguageManagerInterface $language_manager) {
$this->languageManager = $language_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('language_manager'));
}
/**
* {@inheritdoc}
*/
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);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
LanguageDropdownBlock:: |
protected | property | The language manager service. | |
LanguageDropdownBlock:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
LanguageDropdownBlock:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
LanguageDropdownBlock:: |
public | function | Constructs new LanguageDropdownBlock. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |