WSFieldLocalAction.php in Web Service Data 2.0.x
Same filename and directory in other branches
Namespace
Drupal\wsdata_field\Plugin\DerivativeFile
modules/wsdata_field/src/Plugin/Derivative/WSFieldLocalAction.phpView source
<?php
namespace Drupal\wsdata_field\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Symfony\Component\DependencyInjection\ContainerInterface;
/**
* Provides local action definitions for all entity bundles.
*/
class WSFieldLocalAction extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Constructs a WSFieldLocalAction object.
*
* @param \Drupal\Core\Routing\RouteProviderInterface $route_provider
* The route provider to load routes by name.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
*/
public function __construct(RouteProviderInterface $route_provider, EntityTypeManagerInterface $entity_type_manager) {
$this->routeProvider = $route_provider;
$this->entityTypeManager = $entity_type_manager;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('router.route_provider'), $container
->get('entity_type.manager'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type
->get('field_ui_base_route')) {
$this->derivatives["field_wsfield_config_add_{$entity_type_id}"] = [
'route_name' => "wsdata_field.field_wsfield_config_add_{$entity_type_id}",
'title' => $this
->t('Add web service field'),
'appears_on' => [
"entity.{$entity_type_id}.field_ui_fields",
],
];
}
}
foreach ($this->derivatives as &$entry) {
$entry += $base_plugin_definition;
}
return $this->derivatives;
}
}
Classes
Name![]() |
Description |
---|---|
WSFieldLocalAction | Provides local action definitions for all entity bundles. |