ChangeUserRoleTrait.php in Administer Users by Role 8.3
File
src/Plugin/Action/ChangeUserRoleTrait.php
View source
<?php
namespace Drupal\administerusersbyrole\Plugin\Action;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Session\AccountInterface;
trait ChangeUserRoleTrait {
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
$access = parent::access($object, $account, TRUE)
->orIf(administerusersbyrole_user_assign_role($object, $account, [
$this->configuration['rid'],
]));
return $return_as_object ? $access : $access
->isAllowed();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$allowed = \Drupal::service('administerusersbyrole.access')
->listRoles('role-assign', \Drupal::currentUser());
$form['rid']['#options'] = array_intersect_key($form['rid']['#options'], array_flip($allowed));
return $form;
}
}