diff --git a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php index 22e3cca..f50d874 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php +++ b/core/modules/system/lib/Drupal/system/Plugin/views/field/BulkFormBase.php @@ -134,7 +134,11 @@ public function views_form(&$form, &$form_state) { * @return array * An associative array of operations, suitable for a select element. */ - abstract protected function getBulkOptions(); + protected function getBulkOptions() { + return array_map(function ($action) { + return $action->label(); + }, $this->actions); + } /** * Submit handler for the bulk form. @@ -159,7 +163,7 @@ public function views_form_submit(&$form, &$form_state) { $operation_definition = $action->getPluginDefinition(); if (!empty($operation_definition['confirm_form_path'])) { - $form_state['confirm_form_path'] = $operation_definition['confirm_form_path']; + $form_state['redirect'] = $operation_definition['confirm_form_path']; } } } diff --git a/core/modules/user/lib/Drupal/user/Plugin/Action/AddRoleUser.php b/core/modules/user/lib/Drupal/user/Plugin/Action/AddRoleUser.php index f1d1f37..0288ce4 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Action/AddRoleUser.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Action/AddRoleUser.php @@ -28,12 +28,9 @@ class AddRoleUser extends ChangeUserRoleBase { public function execute($account = NULL) { $rid = $this->configuration['rid']; // Skip adding the role to the user if they already have it. - if ($account !== FALSE && !isset($account->roles[$rid])) { - $roles = $account->roles + array($rid => $rid); - // For efficiency manually save the original account before applying - // any changes. + if (array_search($rid, $account->getBCEntity()->roles) === FALSE) { $account->original = clone $account; - $account->roles = $roles; + $account->roles[] = $rid; $account->save(); } } diff --git a/core/modules/user/lib/Drupal/user/Plugin/Action/RemoveRoleUser.php b/core/modules/user/lib/Drupal/user/Plugin/Action/RemoveRoleUser.php index a2b2616..2c200e6 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/Action/RemoveRoleUser.php +++ b/core/modules/user/lib/Drupal/user/Plugin/Action/RemoveRoleUser.php @@ -28,12 +28,10 @@ class RemoveRoleUser extends ChangeUserRoleBase { 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 && isset($account->roles[$rid])) { - $roles = array_diff($account->roles, array($rid => $rid)); - // For efficiency manually save the original account before applying - // any changes. + $key = array_search($rid, $account->getBCEntity()->roles); + if ($key !== FALSE) { $account->original = clone $account; - $account->roles = $roles; + unset($account->roles[$key]); $account->save(); } } diff --git a/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php b/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php index 79ab932..4fde987 100644 --- a/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php +++ b/core/modules/user/lib/Drupal/user/Plugin/views/field/UserBulkForm.php @@ -8,9 +8,9 @@ namespace Drupal\user\Plugin\views\field; use Drupal\Component\Annotation\PluginID; -use Drupal\Core\Extension\ModuleHandlerInterface; +use Drupal\Core\Entity\EntityManager; use Drupal\system\Plugin\views\field\BulkFormBase; -use Drupal\user\Plugin\Core\Entity\User as UserEntity; +use Drupal\user\UserInterface; use Symfony\Component\DependencyInjection\ContainerInterface; /** @@ -21,38 +21,16 @@ class UserBulkForm extends BulkFormBase { /** - * The module handler - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** * {@inheritdoc} - * - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler. */ - public function __construct(array $configuration, $plugin_id, array $plugin_definition, ModuleHandlerInterface $module_handler) { - parent::__construct($configuration, $plugin_id, $plugin_definition); + public function __construct(array $configuration, $plugin_id, array $plugin_definition, EntityManager $manager) { + parent::__construct($configuration, $plugin_id, $plugin_definition, $manager); - $this->moduleHandler = $module_handler; - } + // Filter the actions to only include those for the 'user' entity type. + $this->actions = array_filter($this->actions, function ($action) { + return $action->getType() == 'user'; + }); - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, array $plugin_definition) { - return new static($configuration, $plugin_id, $plugin_definition, $container->get('module_handler')); - } - - /** - * {@inheritdoc} - */ - protected function getBulkOptions() { - return array_map(function($operation) { - return $operation['label']; - }, $this->moduleHandler->invokeAll('user_operations')); } /** @@ -66,7 +44,7 @@ public function views_form(&$form, &$form_state) { if (!empty($this->view->result)) { foreach ($this->view->result as $row_index => $result) { $account = $result->_entity; - if ($account instanceof UserEntity) { + if ($account instanceof UserInterface) { $form[$this->options['id']][$row_index]['#title'] = t('Update the user %name', array('%name' => $account->label())); } } @@ -79,46 +57,9 @@ public function views_form(&$form, &$form_state) { */ public function views_form_validate(&$form, &$form_state) { $selected = array_filter($form_state['values'][$this->options['id']]); - if (count($selected) == 0) { + if (empty($selected)) { form_set_error('', t('No users selected.')); } } - /** - * {@inheritdoc} - */ - public function views_form_submit(&$form, &$form_state) { - if ($form_state['step'] == 'views_form_views_form') { - // Filter only selected checkboxes. - $selected = array_filter($form_state['values'][$this->options['id']]); - $accounts = array(); - foreach (array_intersect_key($this->view->result, $selected) as $result) { - if ($account = $this->get_entity($result)) { - $accounts[$account->id()] = $account; - } - } - - $operations = $this->moduleHandler->invokeAll('user_operations', array($form_state['values']['action'])); - $operation = $operations[$form_state['values']['action']]; - // Filter out unchecked accounts. - if ($function = $operation['callback']) { - // Add in callback arguments if present. - if (isset($operation['callback arguments'])) { - $args = array_merge(array($accounts), $operation['callback arguments']); - } - else { - $args = array($accounts); - } - call_user_func_array($function, $args); - - if (isset($operation['redirect'])) { - $form_state['redirect'] = $operation['redirect']; - } - else { - drupal_set_message(format_plural(count($accounts), 'One account was blocked.', '@count accounts were blocked.')); - } - } - } - } - }