3 namespace Drupal\entityqueue\Plugin\Derivative;
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityTypeManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Drupal\Core\StringTranslation\StringTranslationTrait;
9 use Drupal\Core\StringTranslation\TranslationInterface;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
13 * Provides local task definitions for all entity bundles.
15 class EntityqueueLocalTask extends DeriverBase implements ContainerDeriverInterface {
17 use StringTranslationTrait;
20 * The entity type manager.
22 * @var \Drupal\Core\Entity\EntityTypeManagerInterface
24 protected $entityTypeManager;
27 * Creates an EntityqueueLocalTask object.
29 * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
31 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
32 * The translation manager.
34 public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
35 $this->entityTypeManager = $entity_type_manager;
36 $this->stringTranslation = $string_translation;
42 public static function create(ContainerInterface $container, $base_plugin_id) {
44 $container->get('entity_type.manager'),
45 $container->get('string_translation')
52 public function getDerivativeDefinitions($base_plugin_definition) {
53 $this->derivatives = [];
55 foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
56 if ($entity_type->hasViewBuilderClass() && $entity_type->hasLinkTemplate('canonical')) {
57 $entityqueue_route_name = "entity.$entity_type_id.entityqueue";
58 $this->derivatives[$entityqueue_route_name] = [
59 'entity_type' => $entity_type_id,
60 'title' => $this->t('Entityqueue'),
61 'route_name' => $entityqueue_route_name,
62 'base_route' => "entity.$entity_type_id.canonical",
63 // Ensure that the entityqueue tab is at the end of the list.
65 ] + $base_plugin_definition;
69 return parent::getDerivativeDefinitions($base_plugin_definition);