By keerthi kumar on
Change record status:
Draft (View all draft change records)
Project:
Introduced in branch:
12.1.x
Introduced in version:
12.1.0
Issue links:
Description:
Returning a value from FormInterface::submitForm() is deprecated in drupal:12.1.0 and is removed from drupal:13.0.0.
FormInterface::submitForm() now has @return void. Form API ignores the returned value. FormSubmitter::executeSubmitHandlers() triggers a deprecation when a submitForm() handler returns a non-null value.
Before:
public function submitForm(array &$form, FormStateInterface $form_state) {
parent::submitForm($form, $form_state);
return $this->entity;
}After:
public function submitForm(array &$form, FormStateInterface $form_state): void {
parent::submitForm($form, $form_state);
}
Some modules use submitForm() as both the submit handler and the #ajax callback, and return an AjaxResponse or a render array. Move the AJAX code into its own method and point #ajax at it:
$form['actions']['submit']['#ajax'] = [
'callback' => '::ajaxCallback',
];
public function ajaxCallback(array &$form, FormStateInterface $form_state): AjaxResponse {
$response = new AjaxResponse();
// Build the response.
return $response;
}
Submit handlers that need a response or redirect can call $form_state->setResponse() or $form_state->setRedirect().
Impacts:
Module developers