Version 1
[yaffs-website] / web / modules / contrib / entity / src / Plugin / Derivative / RevisionsOverviewDeriver.php
1 <?php
2
3 namespace Drupal\entity\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
7 use Symfony\Component\DependencyInjection\ContainerInterface;
8
9 /**
10  * Provides local tasks for the revision overview.
11  */
12 class RevisionsOverviewDeriver extends DeriverBase implements ContainerDeriverInterface {
13
14   /**
15    * The entity type manager.
16    *
17    * @var \Drupal\Core\Entity\EntityTypeManagerInterface
18    */
19   protected $entityTypeManager;
20
21   /**
22    * Creates a new RevisionsOverviewDeriver instance.
23    *
24    * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager
25    *   The entity type manager.
26    */
27   public function __construct(\Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager) {
28     $this->entityTypeManager = $entityTypeManager;
29   }
30
31   /**
32    * {@inheritdoc}
33    */
34   public static function create(ContainerInterface $container, $base_plugin_id) {
35     return new static(
36       $container->get('entity_type.manager')
37     );
38   }
39
40   /**
41    * {@inheritdoc}
42    */
43   public function getDerivativeDefinitions($base_plugin_definition) {
44     $exclude = ['node'];
45
46     $this->derivatives = [];
47     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
48       if (in_array($entity_type_id, $exclude)) {
49         continue;
50       }
51
52       if (!$entity_type->hasLinkTemplate('version-history')) {
53         continue;
54       }
55
56       $this->derivatives[$entity_type_id] = [
57         'route_name' => "entity.$entity_type_id.version_history",
58         'title' => 'Revisions',
59         'base_route' => "entity.$entity_type_id.canonical",
60         'weight' => 20,
61       ] + $base_plugin_definition;
62     }
63
64     return parent::getDerivativeDefinitions($base_plugin_definition);
65   }
66
67 }