3 namespace Drupal\content_translation\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
7 use Drupal\content_translation\ContentTranslationManagerInterface;
8 use Symfony\Component\DependencyInjection\ContainerInterface;
11 * Provides dynamic contextual links for content translation.
13 * @see \Drupal\content_translation\Plugin\Menu\ContextualLink\ContentTranslationContextualLinks
15 class ContentTranslationContextualLinks extends DeriverBase implements ContainerDeriverInterface {
18 * The content translation manager.
20 * @var \Drupal\content_translation\ContentTranslationManagerInterface
22 protected $contentTranslationManager;
25 * Constructs a new ContentTranslationContextualLinks.
27 * @param \Drupal\content_translation\ContentTranslationManagerInterface $content_translation_manager
28 * The content translation manager.
30 public function __construct(ContentTranslationManagerInterface $content_translation_manager) {
31 $this->contentTranslationManager = $content_translation_manager;
37 public static function create(ContainerInterface $container, $base_plugin_id) {
39 $container->get('content_translation.manager')
46 public function getDerivativeDefinitions($base_plugin_definition) {
47 // Create contextual links for translatable entity types.
48 foreach ($this->contentTranslationManager->getSupportedEntityTypes() as $entity_type_id => $entity_type) {
49 $this->derivatives[$entity_type_id]['title'] = t('Translate');
50 $this->derivatives[$entity_type_id]['route_name'] = "entity.$entity_type_id.content_translation_overview";
51 $this->derivatives[$entity_type_id]['group'] = $entity_type_id;
53 return parent::getDerivativeDefinitions($base_plugin_definition);