class EntityUsageLocalTask in Entity Usage 8
Same name and namespace in other branches
- 8.4 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask
- 8.2 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask
- 8.3 src/Plugin/Derivative/EntityUsageLocalTask.php \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask
Provides local task definitions for all entity types.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\entity_usage\Plugin\Derivative\EntityUsageLocalTask implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of EntityUsageLocalTask
1 string reference to 'EntityUsageLocalTask'
File
- src/
Plugin/ Derivative/ EntityUsageLocalTask.php, line 15
Namespace
Drupal\entity_usage\Plugin\DerivativeView source
class EntityUsageLocalTask extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* The config factory service.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $config;
/**
* Creates an EntityUsageLocalTask object.
*
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity manager.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config
* The config factory service.
*/
public function __construct(EntityTypeManagerInterface $entity_type_manager, ConfigFactoryInterface $config) {
$this->entityTypeManager = $entity_type_manager;
$this->config = $config;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container
->get('entity_type.manager'), $container
->get('config.factory'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
$configured_types = $this->config
->get('entity_usage.settings')
->get('local_task_enabled_entity_types') ?: [];
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if ($entity_type
->hasLinkTemplate('canonical')) {
if (!in_array($entity_type_id, $configured_types)) {
continue;
}
$this->derivatives["{$entity_type_id}.entity_usage"] = [
'route_name' => "entity.{$entity_type_id}.entity_usage",
'title' => $this
->t('Usage'),
'base_route' => "entity.{$entity_type_id}.canonical",
'weight' => 99,
];
}
}
foreach ($this->derivatives as &$entry) {
$entry += $base_plugin_definition;
}
return $this->derivatives;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DeriverBase:: |
protected | property | List of derivative definitions. | 1 |
DeriverBase:: |
public | function |
Gets the definition of a derivative plugin. Overrides DeriverInterface:: |
|
EntityUsageLocalTask:: |
protected | property | The config factory service. | |
EntityUsageLocalTask:: |
protected | property | The entity type manager. | |
EntityUsageLocalTask:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
EntityUsageLocalTask:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
EntityUsageLocalTask:: |
public | function | Creates an EntityUsageLocalTask object. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |