5a88d91d0abde3a4c2d36262be679d2b48b76f79
[yaffs-website] / web / core / modules / config_translation / src / Plugin / Menu / LocalTask / ConfigTranslationLocalTask.php
1 <?php
2
3 namespace Drupal\config_translation\Plugin\Menu\LocalTask;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Menu\LocalTaskDefault;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8
9 /**
10  * Defines a local task plugin with a dynamic title.
11  */
12 class ConfigTranslationLocalTask extends LocalTaskDefault {
13   use StringTranslationTrait;
14
15   /**
16    * The mapper plugin discovery service.
17    *
18    * @var \Drupal\config_translation\ConfigMapperManagerInterface
19    */
20   protected $mapperManager;
21
22   /**
23    * {@inheritdoc}
24    */
25   public function getTitle() {
26     // Take custom 'config_translation_plugin_id' plugin definition key to
27     // retrieve title. We need to retrieve a runtime title (as opposed to
28     // storing the title on the plugin definition for the link) because
29     // it contains translated parts that we need in the runtime language.
30     $type_name = Unicode::strtolower($this->mapperManager()->createInstance($this->pluginDefinition['config_translation_plugin_id'])->getTypeLabel());
31     return $this->t('Translate @type_name', ['@type_name' => $type_name]);
32   }
33
34   /**
35    * Gets the mapper manager.
36    *
37    * @return \Drupal\config_translation\ConfigMapperManagerInterface
38    *   The mapper manager.
39    */
40   protected function mapperManager() {
41     if (!$this->mapperManager) {
42       $this->mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
43     }
44     return $this->mapperManager;
45   }
46
47 }