class PreviewLinkTasks in Preview Link 8
Preview link task generation.
Hierarchy
- class \Drupal\Component\Plugin\Derivative\DeriverBase implements DeriverInterface
- class \Drupal\preview_link\Plugin\Derivative\PreviewLinkTasks implements ContainerDeriverInterface uses StringTranslationTrait
Expanded class hierarchy of PreviewLinkTasks
1 string reference to 'PreviewLinkTasks'
File
- src/
Plugin/ Derivative/ PreviewLinkTasks.php, line 16
Namespace
Drupal\preview_link\Plugin\DerivativeView source
class PreviewLinkTasks 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->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
if (!$this
->supportsPreviewLink($entity_type)) {
continue;
}
$this->derivatives["{$entity_type_id}.generate_preview_link"] = [
'route_name' => "entity.{$entity_type_id}.generate_preview_link",
'title' => $this
->t('Preview Link'),
'base_route' => "entity.{$entity_type_id}.canonical",
'weight' => 30,
] + $base_plugin_definition;
}
return $this->derivatives;
}
/**
* Check if the entity type is supported.
*
* @param \Drupal\Core\Entity\EntityTypeInterface $entityType
* The entity type we're checking.
*
* @return bool
* TRUE if it supports previews otherwise FALSE.
*/
protected function supportsPreviewLink(EntityTypeInterface $entityType) {
return $entityType
->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:: |
|
PreviewLinkTasks:: |
protected | property | The base plugin ID. | |
PreviewLinkTasks:: |
protected | property | The entity type manager. | |
PreviewLinkTasks:: |
public static | function |
Creates a new class instance. Overrides ContainerDeriverInterface:: |
|
PreviewLinkTasks:: |
public | function |
Gets the definition of all derivatives of a base plugin. Overrides DeriverBase:: |
|
PreviewLinkTasks:: |
protected | function | Check if the entity type is supported. | |
PreviewLinkTasks:: |
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. |