class AddRoleUser

Adds a role to a user.

Plugin annotation


@Action(
  id = "user_add_role_action",
  label = @Translation("Add a role to the selected users"),
  type = "user"
)

Hierarchy

Expanded class hierarchy of AddRoleUser

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

File

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

Namespace

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

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

    // Skip adding the role to the user if they already have it.
    if ($account !== FALSE && !$account
      ->hasRole($rid)) {

      // For efficiency manually save the original account before applying
      // any changes.
      $account->original = clone $account;
      $account
        ->addRole($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
AddRoleUser::execute public function Executes the plugin. Overrides ExecutableInterface::execute
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