Updated all the contrib modules to their latest versions.
[yaffs-website] / web / modules / contrib / entityqueue / src / Plugin / Derivative / EntityqueueLocalTask.php
1 <?php
2
3 namespace Drupal\entityqueue\Plugin\Derivative;
4
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;
11
12 /**
13  * Provides local task definitions for all entity bundles.
14  */
15 class EntityqueueLocalTask extends DeriverBase implements ContainerDeriverInterface {
16
17   use StringTranslationTrait;
18
19   /**
20    * The entity type manager.
21    *
22    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
23    */
24   protected $entityTypeManager;
25
26   /**
27    * Creates an EntityqueueLocalTask object.
28    *
29    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
30    *   The entity manager.
31    * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
32    *   The translation manager.
33    */
34   public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
35     $this->entityTypeManager = $entity_type_manager;
36     $this->stringTranslation = $string_translation;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public static function create(ContainerInterface $container, $base_plugin_id) {
43     return new static(
44       $container->get('entity_type.manager'),
45       $container->get('string_translation')
46     );
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getDerivativeDefinitions($base_plugin_definition) {
53     $this->derivatives = [];
54
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.
64           'weight' => 21,
65         ] + $base_plugin_definition;
66       }
67     }
68
69     return parent::getDerivativeDefinitions($base_plugin_definition);
70   }
71
72 }