public function UserBulkForm::viewsFormSubmit in Open Social 8
Same name and namespace in other branches
- 8.2 modules/social_features/social_user_export/src/Plugin/views/field/UserBulkForm.php \Drupal\social_user_export\Plugin\views\field\UserBulkForm::viewsFormSubmit()
- 8.3 modules/social_features/social_user_export/src/Plugin/views/field/UserBulkForm.php \Drupal\social_user_export\Plugin\views\field\UserBulkForm::viewsFormSubmit()
- 8.4 modules/social_features/social_user_export/src/Plugin/views/field/UserBulkForm.php \Drupal\social_user_export\Plugin\views\field\UserBulkForm::viewsFormSubmit()
Submit handler for the bulk form.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Throws
\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException Thrown when the user tried to access an action without access to it.
Overrides BulkForm::viewsFormSubmit
File
- modules/
social_features/ social_user_export/ src/ Plugin/ views/ field/ UserBulkForm.php, line 18
Class
- UserBulkForm
- Defines a user operations bulk form element.
Namespace
Drupal\social_user_export\Plugin\views\fieldCode
public function viewsFormSubmit(&$form, FormStateInterface $form_state) {
if ($form_state
->get('step') == 'views_form_views_form') {
// Filter only selected checkboxes.
$selected = array_filter($form_state
->getValue($this->options['id']));
$entities = [];
$action = $this->actions[$form_state
->getValue('action')];
$count = 0;
// Check whether all the selected users.
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);
// Skip execution if the user did not have access.
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 {
// Don't display the message unless there are some elements affected and
// there is no confirmation form.
if ($count) {
drupal_set_message($this
->formatPlural($count, '%action was applied to @count item.', '%action was applied to @count items.', [
'%action' => $action
->label(),
]));
}
}
}
}