You are here

class SocialRemoveRoleUser in Open Social 10.1.x

Same name and namespace in other branches
  1. 8.9 modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser
  2. 8.7 modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser
  3. 8.8 modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser
  4. 10.3.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser
  5. 10.0.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser
  6. 10.2.x modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php \Drupal\social_user\Plugin\Action\SocialRemoveRoleUser

Removes a role from a user but restricted by role.

Plugin annotation


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

Hierarchy

Expanded class hierarchy of SocialRemoveRoleUser

1 file declares its use of SocialRemoveRoleUser
social_user.module in modules/social_features/social_user/social_user.module
The social user module alterations.

File

modules/social_features/social_user/src/Plugin/Action/SocialRemoveRoleUser.php, line 23

Namespace

Drupal\social_user\Plugin\Action
View source
class SocialRemoveRoleUser extends ChangeUserRoleBase implements ContainerFactoryPluginInterface {

  /**
   * The account proxy interface.
   *
   * @var \Drupal\Core\Session\AccountProxyInterface
   */
  protected $currentUser;

  /**
   * The role delegation delegatable roles interface.
   *
   * @var \Drupal\role_delegation\DelegatableRolesInterface
   */
  protected $delegatableRoles;

  /**
   * {@inheritdoc}
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeInterface $entity_type, AccountProxyInterface $currentUser, DelegatableRolesInterface $delegatableRoles) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $entity_type);
    $this->entityType = $entity_type;
    $this->currentUser = $currentUser
      ->getAccount();
    $this->delegatableRoles = $delegatableRoles;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    return new static($configuration, $plugin_id, $plugin_definition, $container
      ->get('entity_type.manager')
      ->getDefinition('user_role'), $container
      ->get('current_user'), $container
      ->get('delegatable_roles'));
  }

  /**
   * {@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();
    }
  }

  /**
   * {@inheritdoc}
   */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $roles = $this->delegatableRoles
      ->getAssignableRoles($this->currentUser);

    // Remove the authenticated role.
    unset($roles[RoleInterface::AUTHENTICATED_ID]);
    $form['rid'] = [
      '#type' => 'radios',
      '#title' => t('Role'),
      '#options' => $roles,
      '#default_value' => $this->configuration['rid'],
      '#required' => TRUE,
    ];
    return $form;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ActionBase::executeMultiple public function Executes the plugin for an array of objects. Overrides ActionInterface::executeMultiple 3
ChangeUserRoleBase::$entityType protected property The user role entity type.
ChangeUserRoleBase::access public function Checks object access. Overrides ActionInterface::access
ChangeUserRoleBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides ConfigurableActionBase::calculateDependencies
ChangeUserRoleBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableActionBase::defaultConfiguration
ChangeUserRoleBase::submitConfigurationForm public function Form submission handler. Overrides PluginFormInterface::submitConfigurationForm
ConfigurableActionBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
ConfigurableActionBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
ConfigurableActionBase::validateConfigurationForm public function Form validation handler. Overrides PluginFormInterface::validateConfigurationForm 2
DependencySerializationTrait::$_entityStorages protected property
DependencySerializationTrait::$_serviceIds protected property
DependencySerializationTrait::__sleep public function 2
DependencySerializationTrait::__wakeup public function 2
DependencyTrait::$dependencies protected property The object's dependencies.
DependencyTrait::addDependencies protected function Adds multiple dependencies.
DependencyTrait::addDependency protected function Adds a dependency.
MessengerTrait::$messenger protected property The messenger. 27
MessengerTrait::messenger public function Gets the messenger. 27
MessengerTrait::setMessenger public function Sets the messenger.
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
SocialRemoveRoleUser::$currentUser protected property The account proxy interface.
SocialRemoveRoleUser::$delegatableRoles protected property The role delegation delegatable roles interface.
SocialRemoveRoleUser::buildConfigurationForm public function Form constructor. Overrides ChangeUserRoleBase::buildConfigurationForm
SocialRemoveRoleUser::create public static function Creates an instance of the plugin. Overrides ChangeUserRoleBase::create
SocialRemoveRoleUser::execute public function Executes the plugin. Overrides ExecutableInterface::execute
SocialRemoveRoleUser::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides ChangeUserRoleBase::__construct
StringTranslationTrait::$stringTranslation protected property The string translation service. 4
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.