UserBulkForm.php in Open Social 8.4
File
modules/social_features/social_user_export/src/Plugin/views/field/UserBulkForm.php
View source
<?php
namespace Drupal\social_user_export\Plugin\views\field;
use Drupal\user\Plugin\views\field\UserBulkForm as BaseUserBulkForm;
use Drupal\Core\Form\FormStateInterface;
class UserBulkForm extends BaseUserBulkForm {
public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
if ($form_state
->get('step') == 'views_form_views_form') {
$selected = array_filter($form_state
->getValue($this->options['id']));
$entities = [];
$action = $this->actions[$form_state
->getValue('action')];
$count = 0;
if ($action
->getPlugin()
->getPluginId() == 'social_user_export_user_action') {
$plugin = $action
->getPlugin();
$plugin
->setApplyAll((bool) $form_state
->getValue('select_all'));
$plugin
->setQuery($form_state
->get('query', []));
}
foreach ($selected as $bulk_form_key) {
$entity = $this
->loadEntityFromBulkFormKey($bulk_form_key);
if (!$action
->getPlugin()
->access($entity, $this->view
->getUser())) {
$this
->drupalSetMessage($this
->t('No access to execute %action on the @entity_type_label %entity_label.', [
'%action' => $action
->label(),
'@entity_type_label' => $entity
->getEntityType()
->getLabel(),
'%entity_label' => $entity
->label(),
]), 'error');
continue;
}
$count++;
$entities[$bulk_form_key] = $entity;
}
$action
->execute($entities);
$operation_definition = $action
->getPluginDefinition();
if (!empty($operation_definition['confirm_form_route_name'])) {
$options = [
'query' => $this
->getDestinationArray(),
];
$form_state
->setRedirect($operation_definition['confirm_form_route_name'], [], $options);
}
else {
if ($count) {
drupal_set_message($this
->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', [
'%action' => $action
->label(),
]));
}
}
}
}
}