public function ContributeSettingsForm::submitAjaxForm in Contribute 8
Submit form #ajax callback.
Parameters
array $form: An associative array containing the structure of the form.
\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.
Return value
\Drupal\Core\Ajax\AjaxResponse An Ajax response that display validation error messages or redirects to a URL
File
- src/
Form/ ContributeSettingsForm.php, line 250
Class
- ContributeSettingsForm
- Configure contribute settings for this site.
Namespace
Drupal\contribute\FormCode
public function submitAjaxForm(array &$form, FormStateInterface $form_state) {
if ($form_state
->hasAnyErrors()) {
// Display messages first by prefixing it the form and setting its weight
// to -1000.
$form = [
'status_messages' => [
'#type' => 'status_messages',
'#weight' => -1000,
],
] + $form;
// Remove wrapper.
unset($form['#prefix'], $form['#suffix']);
$response = new AjaxResponse();
$response
->addCommand(new HtmlCommand('#' . $this
->getWrapperId(), $form));
return $response;
}
else {
$response = new AjaxResponse();
$response
->addCommand(new RedirectCommand(Url::fromRoute('system.status')
->toString()));
return $response;
}
}