3 namespace Drupal\field_ui\Plugin\Derivative;
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;
13 * Provides local action definitions for all entity bundles.
15 class FieldUiLocalAction extends DeriverBase implements ContainerDeriverInterface {
17 use StringTranslationTrait;
22 * @var \Drupal\Core\Entity\EntityManagerInterface
24 protected $entityManager;
27 * Constructs a FieldUiLocalAction object.
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
34 public function __construct(RouteProviderInterface $route_provider, EntityManagerInterface $entity_manager) {
35 $this->routeProvider = $route_provider;
36 $this->entityManager = $entity_manager;
42 public static function create(ContainerInterface $container, $base_plugin_id) {
44 $container->get('router.route_provider'),
45 $container->get('entity.manager')
52 public function getDerivativeDefinitions($base_plugin_definition) {
53 $this->derivatives = [];
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"],
65 foreach ($this->derivatives as &$entry) {
66 $entry += $base_plugin_definition;
69 return $this->derivatives;