3 namespace Drupal\config_translation\Plugin\Menu\ContextualLink;
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Menu\ContextualLinkDefault;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Symfony\Component\HttpFoundation\Request;
11 * Defines a contextual link plugin with a dynamic title.
13 class ConfigTranslationContextualLink extends ContextualLinkDefault {
14 use StringTranslationTrait;
17 * The mapper plugin discovery service.
19 * @var \Drupal\config_translation\ConfigMapperManagerInterface
21 protected $mapperManager;
26 public function getTitle(Request $request = NULL) {
27 // Use the custom 'config_translation_plugin_id' plugin definition key to
28 // retrieve the title. We need to retrieve a runtime title (as opposed to
29 // storing the title on the plugin definition for the link) because it
30 // contains translated parts that we need in the runtime language.
31 $type_name = Unicode::strtolower($this->mapperManager()->createInstance($this->pluginDefinition['config_translation_plugin_id'])->getTypeLabel());
32 return $this->t('Translate @type_name', ['@type_name' => $type_name]);
36 * Gets the mapper manager.
38 * @return \Drupal\config_translation\ConfigMapperManagerInterface
41 protected function mapperManager() {
42 if (!$this->mapperManager) {
43 $this->mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
45 return $this->mapperManager;