Mercurial > hg > isophonics-drupal-site
annotate core/modules/language/src/Plugin/Derivative/LanguageBlock.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 4c8ae668cc8c |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@0 | 2 |
Chris@0 | 3 namespace Drupal\language\Plugin\Derivative; |
Chris@0 | 4 |
Chris@0 | 5 use Drupal\Component\Plugin\Derivative\DeriverBase; |
Chris@0 | 6 use Drupal\language\ConfigurableLanguageManagerInterface; |
Chris@0 | 7 |
Chris@0 | 8 /** |
Chris@0 | 9 * Provides language switcher block plugin definitions for all languages. |
Chris@0 | 10 */ |
Chris@0 | 11 class LanguageBlock extends DeriverBase { |
Chris@0 | 12 |
Chris@0 | 13 /** |
Chris@0 | 14 * {@inheritdoc} |
Chris@0 | 15 */ |
Chris@0 | 16 public function getDerivativeDefinitions($base_plugin_definition) { |
Chris@0 | 17 $language_manager = \Drupal::languageManager(); |
Chris@0 | 18 |
Chris@0 | 19 if ($language_manager instanceof ConfigurableLanguageManagerInterface) { |
Chris@0 | 20 $info = $language_manager->getDefinedLanguageTypesInfo(); |
Chris@0 | 21 $configurable_types = $language_manager->getLanguageTypes(); |
Chris@0 | 22 foreach ($configurable_types as $type) { |
Chris@0 | 23 $this->derivatives[$type] = $base_plugin_definition; |
Chris@0 | 24 $this->derivatives[$type]['admin_label'] = t('Language switcher (@type)', ['@type' => $info[$type]['name']]); |
Chris@0 | 25 } |
Chris@0 | 26 // If there is just one configurable type then change the title of the |
Chris@0 | 27 // block. |
Chris@0 | 28 if (count($configurable_types) == 1) { |
Chris@0 | 29 $this->derivatives[reset($configurable_types)]['admin_label'] = t('Language switcher'); |
Chris@0 | 30 } |
Chris@0 | 31 } |
Chris@0 | 32 |
Chris@0 | 33 return parent::getDerivativeDefinitions($base_plugin_definition); |
Chris@0 | 34 } |
Chris@0 | 35 |
Chris@0 | 36 } |