You are here

public function RoleDelegationUserBulkForm::init in Role Delegation 8

Initialize the plugin.

Parameters

\Drupal\views\ViewExecutable $view: The view object.

\Drupal\views\Plugin\views\display\DisplayPluginBase $display: The display handler.

array $options: The options configured for this plugin.

Overrides BulkForm::init

File

src/Plugin/views/field/RoleDelegationUserBulkForm.php, line 57

Class

RoleDelegationUserBulkForm
Defines a user operations bulk form element.

Namespace

Drupal\role_delegation\Plugin\views\field

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
  parent::init($view, $display, $options);
  $entity_type = $this
    ->getEntityType();

  // Filter the actions to only include those for this entity type.

  /** @var \Drupal\system\ActionConfigEntityInterface[] $actions */
  $actions = $this->actionStorage
    ->loadMultiple();
  $this->actions = array_filter($actions, function ($action) use ($entity_type) {
    $plugin_definition = $action
      ->getPluginDefinition();
    if ('user' === $action
      ->getType() && in_array($plugin_definition['id'], [
      'user_add_role_action',
      'user_remove_role_action',
    ])) {
      $collections = $action
        ->getPluginCollections();
      $collection = reset($collections);
      $configuration = $collection
        ->getConfiguration();
      return $this->currentUser
        ->hasPermission('assign all roles') || $this->currentUser
        ->hasPermission(sprintf('assign %s role', $configuration['rid']));
    }
    else {
      return $action
        ->getType() == $entity_type;
    }
  });
}