class RemoveRoleUser

Removes a role from a user.

Plugin annotation


@Action(
  id = "user_remove_role_action",
  label = @Translation("Remove a role from the selected users"),
  type = "user"
)

Hierarchy

Expanded class hierarchy of RemoveRoleUser

1 file declares its use of RemoveRoleUser
RemoveRoleUserTest.php in drupal/core/modules/user/tests/Drupal/user/Tests/Plugin/Action/RemoveRoleUserTest.php
Contains \Drupal\user\Tests\Plugin\Action\RemoveRoleUserTest.

File

drupal/core/modules/user/lib/Drupal/user/Plugin/Action/RemoveRoleUser.php, line 23
Contains \Drupal\user\Plugin\Action\RemoveRoleUser.

Namespace

Drupal\user\Plugin\Action
View source
class RemoveRoleUser extends ChangeUserRoleBase {

  /**
   * {@inheritdoc}
   */
  public function execute($account = NULL) {
    $rid = $this->configuration['rid'];

    // Skip removing the role from the user if they already don't have it.
    if ($account !== FALSE && $account
      ->hasRole($rid)) {

      // For efficiency manually save the original account before applying
      // any changes.
      $account->original = clone $account;
      $account
        ->removeRole($rid);
      $account
        ->save();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionBase::executeMultiple public function Executes the plugin for an array of objects. Overrides ActionInterface::executeMultiple 2
ChangeUserRoleBase::form public function Form constructor. Overrides ConfigurableActionInterface::form
ChangeUserRoleBase::getDefaultConfiguration protected function Returns default configuration for this action. Overrides ConfigurableActionBase::getDefaultConfiguration
ChangeUserRoleBase::submit public function Form submission handler. Overrides ConfigurableActionInterface::submit
ConfigurableActionBase::getConfiguration public function Returns this plugin's configuration. Overrides ConfigurableActionInterface::getConfiguration
ConfigurableActionBase::validate public function Form validation handler. Overrides ConfigurableActionInterface::validate 2
ConfigurableActionBase::__construct public function Constructs a Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct 3
ContainerFactoryPluginBase::create public static function Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface::create 11
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition.
PluginBase::$pluginId protected property The plugin_id.
PluginBase::getPluginDefinition public function Returns the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition
PluginBase::getPluginId public function Returns the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
RemoveRoleUser::execute public function Executes the plugin. Overrides ExecutableInterface::execute