Backup of db before drupal security update
[yaffs-website] / web / core / modules / content_translation / src / Plugin / Derivative / ContentTranslationLocalTasks.php
1 <?php
2
3 namespace Drupal\content_translation\Plugin\Derivative;
4
5 use Drupal\content_translation\ContentTranslationManagerInterface;
6 use Drupal\Component\Plugin\Derivative\DeriverBase;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
9 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 use Drupal\Core\StringTranslation\TranslationInterface;
11
12 /**
13  * Provides dynamic local tasks for content translation.
14  */
15 class ContentTranslationLocalTasks extends DeriverBase implements ContainerDeriverInterface {
16   use StringTranslationTrait;
17
18   /**
19    * The base plugin ID
20    *
21    * @var string
22    */
23   protected $basePluginId;
24
25   /**
26    * The content translation manager.
27    *
28    * @var \Drupal\content_translation\ContentTranslationManagerInterface
29    */
30   protected $contentTranslationManager;
31
32   /**
33    * Constructs a new ContentTranslationLocalTasks.
34    *
35    * @param string $base_plugin_id
36    *   The base plugin ID.
37    * @param \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager
38    *   The content translation manager.
39    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
40    *   The translation manager.
41    */
42   public function __construct($base_plugin_id, ContentTranslationManagerInterface $content_translation_manager, TranslationInterface $string_translation) {
43     $this->basePluginId = $base_plugin_id;
44     $this->contentTranslationManager = $content_translation_manager;
45     $this->stringTranslation = $string_translation;
46   }
47
48   /**
49    * {@inheritdoc}
50    */
51   public static function create(ContainerInterface $container, $base_plugin_id) {
52     return new static(
53       $base_plugin_id,
54       $container->get('content_translation.manager'),
55       $container->get('string_translation')
56     );
57   }
58
59   /**
60    * {@inheritdoc}
61    */
62   public function getDerivativeDefinitions($base_plugin_definition) {
63     // Create tabs for all possible entity types.
64     foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
65       // Find the route name for the translation overview.
66       $translation_route_name = "entity.$entity_type_id.content_translation_overview";
67
68       $base_route_name = "entity.$entity_type_id.canonical";
69       $this->derivatives[$translation_route_name] = [
70         'entity_type' => $entity_type_id,
71         'title' => $this->t('Translate'),
72         'route_name' => $translation_route_name,
73         'base_route' => $base_route_name,
74       ] + $base_plugin_definition;
75     }
76     return parent::getDerivativeDefinitions($base_plugin_definition);
77   }
78
79 }