Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / web / core / modules / config_translation / src / Plugin / Menu / ContextualLink / ConfigTranslationContextualLink.php
1 <?php
2
3 namespace Drupal\config_translation\Plugin\Menu\ContextualLink;
4
5 use Drupal\Component\Utility\Unicode;
6 use Drupal\Core\Menu\ContextualLinkDefault;
7 use Drupal\Core\StringTranslation\StringTranslationTrait;
8 use Symfony\Component\HttpFoundation\Request;
9
10 /**
11  * Defines a contextual link plugin with a dynamic title.
12  */
13 class ConfigTranslationContextualLink extends ContextualLinkDefault {
14   use StringTranslationTrait;
15
16   /**
17    * The mapper plugin discovery service.
18    *
19    * @var \Drupal\config_translation\ConfigMapperManagerInterface
20    */
21   protected $mapperManager;
22
23   /**
24    * {@inheritdoc}
25    */
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]);
33   }
34
35   /**
36    * Gets the mapper manager.
37    *
38    * @return \Drupal\config_translation\ConfigMapperManagerInterface
39    *   The mapper manager.
40    */
41   protected function mapperManager() {
42     if (!$this->mapperManager) {
43       $this->mapperManager = \Drupal::service('plugin.manager.config_translation.mapper');
44     }
45     return $this->mapperManager;
46   }
47
48 }