You are here

class DynamicLocalTasks in Entity Clone 8

Defines dynamic local tasks.

Hierarchy

Expanded class hierarchy of DynamicLocalTasks

1 string reference to 'DynamicLocalTasks'
entity_clone.links.task.yml in ./entity_clone.links.task.yml
entity_clone.links.task.yml

File

src/Plugin/Derivative/DynamicLocalTasks.php, line 14

Namespace

Drupal\entity_clone\Plugin\Derivative
View source
class DynamicLocalTasks extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * The translation manager.
   *
   * @var \Drupal\Core\StringTranslation\TranslationManager
   */
  protected $translationManager;

  /**
   * Constructs a new DynamicLocalTasks.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   * @param \Drupal\Core\StringTranslation\TranslationManager $string_translation
   *   The translation manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager, TranslationManager $string_translation) {
    $this->entityTypeManager = $entity_type_manager;
    $this->translationManager = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, $base_plugin_id) {
    return new static($container
      ->get('entity_type.manager'), $container
      ->get('string_translation'));
  }

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];

    /** @var \Drupal\Core\Entity\EntityTypeInterface $entity_type */
    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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DeriverBase::$derivatives protected property List of derivative definitions. 1
DeriverBase::getDerivativeDefinition public function Gets the definition of a derivative plugin. Overrides DeriverInterface::getDerivativeDefinition
DynamicLocalTasks::$entityTypeManager protected property The entity type manager.
DynamicLocalTasks::$translationManager protected property The translation manager.
DynamicLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
DynamicLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
DynamicLocalTasks::__construct public function Constructs a new DynamicLocalTasks.