class CancelUserAction in Views Bulk Operations (VBO) 8
Same name and namespace in other branches
- 8.3 src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction
- 8.2 src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction
- 4.0.x src/Plugin/Action/CancelUserAction.php \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction
Cancels a user account.
Plugin annotation
@Action(
id = "vbo_cancel_user_action",
label = @Translation("Cancel the selected user accounts"),
type = "user",
)
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase implements ConfigurablePluginInterface, ViewsBulkOperationsActionInterface
- class \Drupal\views_bulk_operations\Plugin\Action\CancelUserAction implements ContainerFactoryPluginInterface, PluginFormInterface
- class \Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase implements ConfigurablePluginInterface, ViewsBulkOperationsActionInterface
- class \Drupal\Core\Action\ActionBase implements ActionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of CancelUserAction
File
- src/
Plugin/ Action/ CancelUserAction.php, line 23
Namespace
Drupal\views_bulk_operations\Plugin\ActionView source
class CancelUserAction extends ViewsBulkOperationsActionBase implements ContainerFactoryPluginInterface, PluginFormInterface {
/**
* The current user.
*
* @var Drupal\Core\Session\AccountInterface
*/
protected $currentUser;
/**
* User module config.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $userConfig;
/**
* Module handler service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Object constructor.
*
* @param array $configuration
* Plugin configuration.
* @param string $plugin_id
* The plugin Id.
* @param mixed $plugin_definition
* Plugin definition.
* @param Drupal\Core\Session\AccountInterface $currentUser
* The current user.
* @param \Drupal\Core\Config\ConfigFactoryInterface $configFactory
* The config factory object.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
* Module handler service.
*/
public function __construct(array $configuration, $plugin_id, $plugin_definition, AccountInterface $currentUser, ConfigFactoryInterface $configFactory, ModuleHandlerInterface $moduleHandler) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->currentUser = $currentUser;
$this->userConfig = $configFactory
->get('user.settings');
$this->moduleHandler = $moduleHandler;
}
/**
* {@inheritdoc}
*/
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
return new static($configuration, $plugin_id, $plugin_definition, $container
->get('current_user'), $container
->get('config.factory'), $container
->get('module_handler'));
}
/**
* {@inheritdoc}
*/
public function execute($account = NULL) {
if ($account
->id() === $this->currentUser
->id() && (empty($this->context['list']) || count($this->context['list'] > 1))) {
drupal_set_message($this
->t('The current user account cannot be canceled in a batch operation. Select your account only or cancel it from your account page.'), 'error');
}
elseif (intval($account
->id()) === 1) {
drupal_set_message($this
->t('The user 1 account (%label) cannot be canceled.', [
'%label' => $account
->label(),
]), 'error');
}
else {
// Allow other modules to act.
if ($this->configuration['user_cancel_method'] != 'user_cancel_delete') {
$this->moduleHandler
->invokeAll('user_cancel', [
$this->configuration,
$account,
$this->configuration['user_cancel_method'],
]);
}
// Cancel the account.
_user_cancel($this->configuration, $account, $this->configuration['user_cancel_method']);
// If current user was cancelled, logout.
if ($account
->id() == $this->currentUser
->id()) {
_user_cancel_session_regenerate();
}
}
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['user_cancel_method'] = [
'#type' => 'radios',
'#title' => $this
->t('When cancelling these accounts'),
];
$form['user_cancel_method'] += user_cancel_methods();
// Allow to send the account cancellation confirmation mail.
$form['user_cancel_confirm'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Require email confirmation to cancel account'),
'#default_value' => FALSE,
'#description' => $this
->t('When enabled, the user must confirm the account cancellation via email.'),
];
// Also allow to send account canceled notification mail, if enabled.
$form['user_cancel_notify'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Notify user when account is canceled'),
'#default_value' => FALSE,
'#access' => $this->userConfig
->get('notify.status_canceled'),
'#description' => $this
->t('When enabled, the user will receive an email notification after the account has been canceled.'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function access($object, AccountInterface $account = NULL, $return_as_object = FALSE) {
/** @var \Drupal\user\UserInterface $object */
return $object
->access('delete', $account, $return_as_object);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CancelUserAction:: |
protected | property | The current user. | |
CancelUserAction:: |
protected | property | Module handler service. | |
CancelUserAction:: |
protected | property | User module config. | |
CancelUserAction:: |
public | function |
Checks object access. Overrides ActionInterface:: |
|
CancelUserAction:: |
public | function |
Form constructor. Overrides PluginFormInterface:: |
|
CancelUserAction:: |
public static | function |
Creates an instance of the plugin. Overrides ContainerFactoryPluginInterface:: |
|
CancelUserAction:: |
public | function |
Executes the plugin. Overrides ExecutableInterface:: |
|
CancelUserAction:: |
public | function |
Object constructor. Overrides PluginBase:: |
|
DependencySerializationTrait:: |
protected | property | An array of entity type IDs keyed by the property name of their storages. | |
DependencySerializationTrait:: |
protected | property | An array of service IDs keyed by property name used for serialization. | |
DependencySerializationTrait:: |
public | function | 1 | |
DependencySerializationTrait:: |
public | function | 2 | |
MessengerTrait:: |
protected | property | The messenger. | 29 |
MessengerTrait:: |
public | function | Gets the messenger. | 29 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
3 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
StringTranslationTrait:: |
protected | property | The string translation service. | 1 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. | |
ViewsBulkOperationsActionBase:: |
protected | property |
Configuration array. Overrides PluginBase:: |
|
ViewsBulkOperationsActionBase:: |
protected | property | Action context. | |
ViewsBulkOperationsActionBase:: |
protected | property | The processed view. | |
ViewsBulkOperationsActionBase:: |
public | function |
Calculates dependencies for the configured plugin. Overrides DependentPluginInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function |
Gets default configuration for this plugin. Overrides ConfigurablePluginInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function |
Execute action on multiple entities. Overrides ActionBase:: |
1 |
ViewsBulkOperationsActionBase:: |
public | function |
Gets this plugin's configuration. Overrides ConfigurablePluginInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function |
Sets the configuration for this plugin instance. Overrides ConfigurablePluginInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function |
Set action context. Overrides ViewsBulkOperationsActionInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function |
Set view object. Overrides ViewsBulkOperationsActionInterface:: |
|
ViewsBulkOperationsActionBase:: |
public | function | Default configuration form submit handler. | 1 |
ViewsBulkOperationsActionBase:: |
public | function | Default configuration form validator. |