You are here

class ScheduledTransitionsLocalTasks in Scheduled Transitions 8

Same name and namespace in other branches
  1. 2.x src/Plugin/Derivative/ScheduledTransitionsLocalTasks.php \Drupal\scheduled_transitions\Plugin\Derivative\ScheduledTransitionsLocalTasks

Scheduled transitions tab for entities.

Hierarchy

Expanded class hierarchy of ScheduledTransitionsLocalTasks

1 string reference to 'ScheduledTransitionsLocalTasks'
scheduled_transitions.links.task.yml in ./scheduled_transitions.links.task.yml
scheduled_transitions.links.task.yml

File

src/Plugin/Derivative/ScheduledTransitionsLocalTasks.php, line 18

Namespace

Drupal\scheduled_transitions\Plugin\Derivative
View source
class ScheduledTransitionsLocalTasks 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 a new ScheduledTransitionsLocalTask.
   *
   * @param string $base_plugin_id
   *   The base plugin ID.
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   Entity type manager.
   */
  public function __construct($base_plugin_id, EntityTypeManagerInterface $entity_type_manager) {
    $this->basePluginId = $base_plugin_id;
    $this->entityTypeManager = $entity_type_manager;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entityType) {
      if ($entityType
        ->hasLinkTemplate(ScheduledTransitionsRouteProvider::LINK_TEMPLATE)) {
        $entityTypeId = $entityType
          ->id();
        $this->derivatives["{$entityTypeId}.scheduled_transitions"] = [
          'class' => ScheduledTransitionsLocalTask::class,
          'route_name' => ScheduledTransitionsRouteProvider::getScheduledTransitionRouteName($entityType),
          // Title is overridden by class.
          'title' => $this
            ->t('Scheduled transitions'),
          'base_route' => "entity.{$entityTypeId}.canonical",
          // Weight it after nodes' Edit, Delete, Versions.
          'weight' => 30,
        ] + $base_plugin_definition;
      }
    }
    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
ScheduledTransitionsLocalTasks::$basePluginId protected property The base plugin ID.
ScheduledTransitionsLocalTasks::$entityTypeManager protected property The entity type manager.
ScheduledTransitionsLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ScheduledTransitionsLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
ScheduledTransitionsLocalTasks::__construct public function Creates a new ScheduledTransitionsLocalTask.
StringTranslationTrait::$stringTranslation protected property The string translation service. 1
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.