Namespace
Drupal\entity_clone\Plugin\Derivative
Fichier
-
src/Plugin/Derivative/DynamicLocalTasks.php
View source
<?php
namespace Drupal\entity_clone\Plugin\Derivative;
use Drupal\Component\Plugin\Derivative\DeriverBase;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Plugin\Discovery\ContainerDeriverInterface;
use Drupal\Core\StringTranslation\TranslationManager;
use Symfony\Component\DependencyInjection\ContainerInterface;
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {
protected $entityTypeManager;
protected $translationManager;
public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationManager $string_translation) {
$this->entityTypeManager = $entity_type_manager;
$this->translationManager = $string_translation;
}
public static function create(ContainerInterface $container, $base_plugin_id) {
return new static($container->get('entity_type.manager'), $container->get('string_translation'));
}
public function getDerivativeDefinitions($base_plugin_definition) {
$this->derivatives = [];
foreach ($this->entityTypeManager
->getDefinitions() as $entity_type_id => $entity_type) {
$has_clone_path = $entity_type->hasLinkTemplate('clone-form');
$has_canonical_path = $entity_type->hasLinkTemplate('canonical');
if ($has_clone_path) {
$this->derivatives["{$entity_type_id}.clone_tab"] = [
'route_name' => "entity.{$entity_type_id}.clone_form",
'title' => $this->translationManager
->translate('Clone'),
'base_route' => "entity.{$entity_type_id}." . ($has_canonical_path ? "canonical" : "edit_form"),
'weight' => 100,
];
}
}
return $this->derivatives;
}
}
Classes