You are here

class ScheduledTransitionsLocalActions in Scheduled Transitions 8

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

Scheduled transitions actions for entities.

Hierarchy

Expanded class hierarchy of ScheduledTransitionsLocalActions

1 string reference to 'ScheduledTransitionsLocalActions'
scheduled_transitions.links.action.yml in ./scheduled_transitions.links.action.yml
scheduled_transitions.links.action.yml

File

src/Plugin/Derivative/ScheduledTransitionsLocalActions.php, line 19

Namespace

Drupal\scheduled_transitions\Plugin\Derivative
View source
class ScheduledTransitionsLocalActions 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 = [];
    $scheduledTransitionDefinition = $this->entityTypeManager
      ->getDefinition('scheduled_transition');
    foreach ($this->entityTypeManager
      ->getDefinitions() as $entityType) {
      if ($entityType
        ->hasLinkTemplate(ScheduledTransitionsRouteProvider::LINK_TEMPLATE)) {
        $entityTypeId = $entityType
          ->id();
        $this->derivatives["{$entityTypeId}.add_scheduled_transition"] = [
          'route_name' => ScheduledTransitionsRouteProvider::getScheduledTransitionAddRouteName($entityType),
          'appears_on' => [
            ScheduledTransitionsRouteProvider::getScheduledTransitionRouteName($entityType),
          ],
          'class' => ScheduledTransitionsLocalAction::class,
          'title' => $this
            ->t('Add @singular', [
            '@singular' => $scheduledTransitionDefinition
              ->getSingularLabel(),
          ]),
          'options' => [
            'attributes' => [
              'class' => [
                'use-ajax',
              ],
              'data-dialog-type' => 'modal',
              'data-dialog-options' => Json::encode([
                'width' => 900,
              ]),
            ],
          ],
        ] + $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
ScheduledTransitionsLocalActions::$basePluginId protected property The base plugin ID.
ScheduledTransitionsLocalActions::$entityTypeManager protected property The entity type manager.
ScheduledTransitionsLocalActions::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
ScheduledTransitionsLocalActions::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
ScheduledTransitionsLocalActions::__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.