class DynamicLocalTasks in Workbench Moderation 8
Same name and namespace in other branches
- 8.2 src/Plugin/Derivative/DynamicLocalTasks.php \Drupal\workbench_moderation\Plugin\Derivative\DynamicLocalTasks
Generates moderation-related local tasks.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\workbench_moderation\Plugin\Derivative\DynamicLocalTasks implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of DynamicLocalTasks
1 string reference to 'DynamicLocalTasks'
File
- src/
Plugin/ Derivative/ DynamicLocalTasks.php, line 18
Namespace
Drupal\workbench_moderation\Plugin\DerivativeView source
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {
use StringTranslationTrait;
/**
* The base plugin ID.
*
* @var string
*/
protected $basePluginId;
/**
* The entity type manager.
*
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* Creates an FieldUiLocalTask object.
*
* @param string $base_plugin_id
* The base plugin ID.
* @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
* The entity type manager.
* @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
* The translation manager.
*/
public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager, TranslationInterface $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->stringTranslation = $string_translation;
$this->basePluginId = $base_plugin_id;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($base_plugin_id, $container
->get('entity_type.manager'), $container
->get('string_translation'));
}
/**
* {@inheritdoc}
*/
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this
->moderatableEntityTypeDefinitions() as $entity_type_id => $entity_type) {
$this->derivatives["{$entity_type_id}.moderation_tab"] = [
'route_name' => "entity.{$entity_type_id}.moderation",
'title' => $this
->t('Manage moderation'),
// @todo - are we sure they all have an edit_form?
'base_route' => "entity.{$entity_type_id}.edit_form",
'weight' => 30,
] + $base_plugin_definition;
}
$latest_version_entities = array_filter($this
->moderatableEntityDefinitions(), function (EntityTypeInterface $type) {
return $type
->hasLinkTemplate('latest-version');
});
foreach ($latest_version_entities as $entity_type_id => $entity_type) {
$this->derivatives["{$entity_type_id}.latest_version_tab"] = [
'route_name' => "entity.{$entity_type_id}.latest_version",
'title' => $this
->t('Latest version'),
'base_route' => "entity.{$entity_type_id}.canonical",
'weight' => 1,
] + $base_plugin_definition;
}
return $this->derivatives;
}
/**
* Returns an array of content entities that are potentially moderateable.
*
* @return \Drupal\Core\Entity\EntityTypeInterface[]
* An array of just those entities we care about.
*/
protected function moderatableEntityDefinitions() {
return array_filter($this->entityTypeManager
->getDefinitions(), function (EntityTypeInterface $type) {
return $type instanceof ContentEntityTypeInterface && $type
->getBundleEntityType() && $type
->isRevisionable();
});
}
/**
* Returns an iterable of config entities representing moderatable content.
*
* @return \Drupal\Core\Entity\EntityTypeInterface[]
* An array of just those entity types we care about.
*/
protected function moderatableEntityTypeDefinitions() {
$entity_types = $this->entityTypeManager
->getDefinitions();
return array_filter($entity_types, function (EntityTypeInterface $type) use ($entity_types) {
return $type instanceof ConfigEntityTypeInterface && ($bundle_of = $type
->get('bundle_of')) && $entity_types[$bundle_of]
->isRevisionable();
});
}
}
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:: |
|
DynamicLocalTasks:: |
protected | property | The base plugin ID. | |
DynamicLocalTasks:: |
protected | property | The entity type manager. | |
DynamicLocalTasks:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
DynamicLocalTasks:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
DynamicLocalTasks:: |
protected | function | Returns an array of content entities that are potentially moderateable. | |
DynamicLocalTasks:: |
protected | function | Returns an iterable of config entities representing moderatable content. | |
DynamicLocalTasks:: |
public | function | Creates an FieldUiLocalTask 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. |