Namespace
Drupal\entity_clone\Plugin\Derivative
File
-
src/Plugin/Derivative/EntityCloneContextualLinks.php
View source
<?php
namespace Drupal\entity_clone\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\TranslationManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class EntityCloneContextualLinks extends DeriverBase implements ContainerDeriverInterface {
protected $entityTypeManager;
protected $translationManager;
public function __construct(EntityTypeManagerInterface $entityTypeManager, TranslationManager $stringTranslation) {
$this->entityTypeManager = $entityTypeManager;
$this->translationManager = $stringTranslation;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container->get('entity_type.manager'), $container->get('string_translation'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives["{$entity_type_id}.clone_tab"] = [
'route_name' => "entity.{$entity_type_id}.clone_form",
'title' => $this->translationManager
->translate('Clone'),
'group' => $entity_type_id,
];
}
return parent::getDerivativeDefinitions($base_plugin_definition);
}
}
Classes