Further Drupal 8.6.4 changes. Some core files were not committed before a commit...
[yaffs-website] / web / core / modules / field_ui / src / Plugin / Derivative / FieldUiLocalAction.php
1 <?php
2
3 namespace Drupal\field_ui\Plugin\Derivative;
4
5 use Drupal\Component\Plugin\Derivative\DeriverBase;
6 use Drupal\Core\Entity\EntityManagerInterface;
7 use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
8 use Drupal\Core\Routing\RouteProviderInterface;
9 use Drupal\Core\StringTranslation\StringTranslationTrait;
10 use Symfony\Component\DependencyInjection\ContainerInterface;
11
12 /**
13  * Provides local action definitions for all entity bundles.
14  */
15 class FieldUiLocalAction extends DeriverBase implements ContainerDeriverInterface {
16
17   use StringTranslationTrait;
18
19   /**
20    * The entity manager
21    *
22    * @var \Drupal\Core\Entity\EntityManagerInterface
23    */
24   protected $entityManager;
25
26   /**
27    * Constructs a FieldUiLocalAction object.
28    *
29    * @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
30    *   The route provider to load routes by name.
31    * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
32    *   The entity manager.
33    */
34   public function __construct(RouteProviderInterface $route_provider, EntityManagerInterface $entity_manager) {
35     $this->routeProvider = $route_provider;
36     $this->entityManager = $entity_manager;
37   }
38
39   /**
40    * {@inheritdoc}
41    */
42   public static function create(ContainerInterface $container, $base_plugin_id) {
43     return new static(
44       $container->get('router.route_provider'),
45       $container->get('entity.manager')
46     );
47   }
48
49   /**
50    * {@inheritdoc}
51    */
52   public function getDerivativeDefinitions($base_plugin_definition) {
53     $this->derivatives = [];
54
55     foreach ($this->entityManager->getDefinitions() as $entity_type_id => $entity_type) {
56       if ($entity_type->get('field_ui_base_route')) {
57         $this->derivatives["field_storage_config_add_$entity_type_id"] = [
58           'route_name' => "field_ui.field_storage_config_add_$entity_type_id",
59           'title' => $this->t('Add field'),
60           'appears_on' => ["entity.$entity_type_id.field_ui_fields"],
61         ];
62       }
63     }
64
65     foreach ($this->derivatives as &$entry) {
66       $entry += $base_plugin_definition;
67     }
68
69     return $this->derivatives;
70   }
71
72 }