You are here

public function RoleAssignUserBulkForm::init in RoleAssign 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/RoleAssignUserBulkForm.php, line 19

Class

RoleAssignUserBulkForm
Defines a user operations bulk form element, with RoleAssign logic applied.

Namespace

Drupal\roleassign\Plugin\views\field

Code

public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) {
  parent::init($view, $display, $options);
  if (roleassign_restrict_access()) {

    // Remove actions that are not allowed based on RoleAssign settings.
    $assignable_roles = array_filter(\Drupal::config('roleassign.settings')
      ->get('roleassign_roles'));
    foreach ($this->actions as $action_key => $action) {
      if (in_array($action
        ->get('plugin'), [
        'user_add_role_action',
        'user_remove_role_action',
      ])) {
        $config = $action
          ->get('configuration');
        if (!in_array($config['rid'], $assignable_roles)) {
          unset($this->actions[$action_key]);
        }
      }
    }
  }
}