public function UserCsvImportForm::submitForm in User CSV import 2.0.x
Same name and namespace in other branches
- 8 src/Form/UserCsvImportForm.php \Drupal\user_csv_import\Form\UserCsvImportForm::submitForm()
- 1.0.x src/Form/UserCsvImportForm.php \Drupal\user_csv_import\Form\UserCsvImportForm::submitForm()
Form submission handler.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Overrides FormInterface::submitForm
File
- src/
Form/ UserCsvImportForm.php, line 275
Class
- UserCsvImportForm
- Provides methods to define and build the user import form.
Namespace
Drupal\user_csv_import\FormCode
public function submitForm(array &$form, FormStateInterface $form_state) {
// Get form data.
$file = $this->file[0];
$roles = $form_state
->getValue([
'config_options',
'roles',
]);
$fields = $form_state
->getValue([
'config_fields',
'fields',
]);
// Construct data to send to the controller.
$config = [
'roles' => array_filter($roles, function ($item) {
return $item;
}),
'fields' => array_filter($fields, function ($item) {
return $item;
}),
'registration_email_type' => $form_state
->getValue([
'config_options',
'registration_email_type',
]),
'password' => $form_state
->getValue([
'config_options',
'password',
]),
'status' => $form_state
->getValue([
'config_options',
'status',
]),
];
// Return success message.
if ($created = UserCsvImportController::processUpload($file, $config)) {
$this->messenger
->addMessage($this
->t('Successfully imported @count users.', [
'@count' => count($created),
]));
}
else {
// Return error message.
$this->messenger
->addMessage($this
->t('No users imported.'));
}
// Redirect to admin users page.
$form_state
->setRedirectUrl(new Url('entity.user.collection'));
}