3 namespace Drupal\config_translation\Plugin\Menu\LocalTask;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Menu\LocalTaskDefault;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 * Defines a local task plugin with a dynamic title.
12 class ConfigTranslationLocalTask extends LocalTaskDefault {
13 use StringTranslationTrait;
16 * The mapper plugin discovery service.
18 * @var \Drupal\config_translation\ConfigMapperManagerInterface
20 protected $mapperManager;
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]);
35 * Gets the mapper manager.
37 * @return \Drupal\config_translation\ConfigMapperManagerInterface
40 protected function mapperManager() {
41 if (!$this->mapperManager) {
42 $this->mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
44 return $this->mapperManager;