You are here

class MultipleRegistrationLocalTasks in Multiple Registration 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/Derivative/MultipleRegistrationLocalTasks.php \Drupal\multiple_registration\Plugin\Derivative\MultipleRegistrationLocalTasks
  2. 3.x src/Plugin/Derivative/MultipleRegistrationLocalTasks.php \Drupal\multiple_registration\Plugin\Derivative\MultipleRegistrationLocalTasks

Defines dynamic local tasks.

Hierarchy

Expanded class hierarchy of MultipleRegistrationLocalTasks

1 string reference to 'MultipleRegistrationLocalTasks'
multiple_registration.links.task.yml in ./multiple_registration.links.task.yml
multiple_registration.links.task.yml

File

src/Plugin/Derivative/MultipleRegistrationLocalTasks.php, line 13

Namespace

Drupal\multiple_registration\Plugin\Derivative
View source
class MultipleRegistrationLocalTasks extends DeriverBase implements ContainerDeriverInterface {
  protected $availableUserRolesService;

  /**
   * The base plugin ID.
   *
   * @var string
   */
  protected $basePluginId;

  /**
   * MultipleRegistrationLocalTasks constructor.
   *
   * @param \Drupal\multiple_registration\AvailableUserRolesService $availableUserRolesService
   *   AvailableUserRolesService service.
   * @param string $base_plugin_id
   *   Base plugin id.
   */
  public function __construct(AvailableUserRolesService $availableUserRolesService, $base_plugin_id) {
    $this->availableUserRolesService = $availableUserRolesService;
    $this->base_plugin_id = $base_plugin_id;
  }

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

  /**
   * {@inheritdoc}
   */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $regPages = $this->availableUserRolesService
      ->getRegistrationPages();
    if (!empty($regPages)) {
      foreach ($regPages as $rid => $role) {
        if ($role['hidden'] === 1) {
          continue;
        }
        $this->derivatives[$rid] = [];
        $this->derivatives[$rid]['title'] = t('Create new @role account', [
          '@role' => $role['role_name'],
        ]);
        $this->derivatives[$rid]['base_route'] = 'user.page';
        $this->derivatives[$rid]['route_name'] = 'multiple_registration.role_registration_page';
        $this->derivatives[$rid]['route_parameters'] = [
          'rid' => $rid,
        ];
      }
    }
    return parent::getDerivativeDefinitions($base_plugin_definition);
  }

}

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
MultipleRegistrationLocalTasks::$availableUserRolesService protected property
MultipleRegistrationLocalTasks::$basePluginId protected property The base plugin ID.
MultipleRegistrationLocalTasks::create public static function Creates a new class instance. Overrides ContainerDeriverInterface::create
MultipleRegistrationLocalTasks::getDerivativeDefinitions public function Gets the definition of all derivatives of a base plugin. Overrides DeriverBase::getDerivativeDefinitions
MultipleRegistrationLocalTasks::__construct public function MultipleRegistrationLocalTasks constructor.