You are here

class MessageSubscribeUiLocalTask in Message Subscribe 8

Provides local tasks for the message subscription UI.

Hierarchy

Expanded class hierarchy of MessageSubscribeUiLocalTask

1 string reference to 'MessageSubscribeUiLocalTask'
message_subscribe_ui.links.task.yml in message_subscribe_ui/message_subscribe_ui.links.task.yml
message_subscribe_ui/message_subscribe_ui.links.task.yml

File

message_subscribe_ui/src/Plugin/Derivative/MessageSubscribeUiLocalTask.php, line 13

Namespace

Drupal\message_subscribe_ui\Plugin\Derivative
View source
class MessageSubscribeUiLocalTask extends DeriverBase implements ContainerDeriverInterface {

  /**
   * The message subscription service.
   *
   * @var \Drupal\message_subscribe\SubscribersInterface
   */
  protected $subscribers;

  /**
   * Constructs the local task deriver.
   *
   * @param \Drupal\message_subscribe\SubscribersInterface $subscribers
   *   The message subscription service.
   */
  public function __construct(SubscribersInterface $subscribers) {
    $this->subscribers = $subscribers;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $this->derivatives = [];
    $first = TRUE;
    foreach ($this->subscribers
      ->getFlags() as $flag) {
      $this->derivatives[$flag
        ->id()] = [
        'title' => $flag
          ->label(),
        // First route gets the same route name as the parent (in order to
        // provide the default tab).
        'route_name' => $first ? 'message_subscribe_ui.tab' : 'message_subscribe_ui.tab.flag',
        'parent_id' => 'message_subscribe_ui.tab',
        'route_parameters' => $first ? [] : [
          'flag' => $flag
            ->id(),
        ],
      ];
      $first = FALSE;
    }
    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
MessageSubscribeUiLocalTask::$subscribers protected property The message subscription service.
MessageSubscribeUiLocalTask::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MessageSubscribeUiLocalTask::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
MessageSubscribeUiLocalTask::__construct public function Constructs the local task deriver.