3 namespace Drupal\content_translation\Plugin\Derivative;
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;
13 * Provides dynamic local tasks for content translation.
15 class ContentTranslationLocalTasks extends DeriverBase implements ContainerDeriverInterface {
16 use StringTranslationTrait;
23 protected $basePluginId;
26 * The content translation manager.
28 * @var \Drupal\content_translation\ContentTranslationManagerInterface
30 protected $contentTranslationManager;
33 * Constructs a new ContentTranslationLocalTasks.
35 * @param string $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.
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;
51 public static function create(ContainerInterface $container, $base_plugin_id) {
54 $container->get('content_translation.manager'),
55 $container->get('string_translation')
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";
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;
76 return parent::getDerivativeDefinitions($base_plugin_definition);