comparison core/modules/language/src/Plugin/Derivative/LanguageBlock.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\language\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\language\ConfigurableLanguageManagerInterface;
7
8 /**
9 * Provides language switcher block plugin definitions for all languages.
10 */
11 class LanguageBlock extends DeriverBase {
12
13 /**
14 * {@inheritdoc}
15 */
16 public function getDerivativeDefinitions($base_plugin_definition) {
17 $language_manager = \Drupal::languageManager();
18
19 if ($language_manager instanceof ConfigurableLanguageManagerInterface) {
20 $info = $language_manager->getDefinedLanguageTypesInfo();
21 $configurable_types = $language_manager->getLanguageTypes();
22 foreach ($configurable_types as $type) {
23 $this->derivatives[$type] = $base_plugin_definition;
24 $this->derivatives[$type]['admin_label'] = t('Language switcher (@type)', ['@type' => $info[$type]['name']]);
25 }
26 // If there is just one configurable type then change the title of the
27 // block.
28 if (count($configurable_types) == 1) {
29 $this->derivatives[reset($configurable_types)]['admin_label'] = t('Language switcher');
30 }
31 }
32
33 return parent::getDerivativeDefinitions($base_plugin_definition);
34 }
35
36 }