Problem/Motivation

There are 182 missingType.return violations for methods implementing \Drupal\Core\Form\FormInterface::submitForm. Ideally the interface would declare void as the return type for this method, however there are some implementations that return a value. There is nothing in core that uses that value.

Proposed resolution

  • Add @return void in FormInterface::submitForm()
  • Trigger a deprecation in \Drupal\Core\Form\FormSubmitter::executeSubmitHandlers when a submit handler returns a non-null value
  • Remove redundant return statements from core submitForm methods (FilterFormatAddForm, FilterFormatEditForm, FilterFormatFormBase, FormTestInputForgeryForm)
  • Remove the 182 resolved entries from core/.phpstan-baseline.php
  • Add test coverage in FormSubmitterTest

Remaining tasks

  • Maintainer review

User interface changes

None

Introduced terminology

None

API changes

Returning a value from a form submit handler is deprecated in drupal:12.1.0 and removed in drupal:13.0.0.

Data model changes

None

Release notes snippet

N/A

Issue fork drupal-3641402

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mstrelan created an issue. See original summary.

keerthi kumar’s picture

I would like to work on this!

keerthi kumar’s picture

Issue summary: View changes
Status: Active » Needs review

I have opened an MR with:
- Added `@return void` docblock to `FormInterface::submitForm()`.
- Removed redundant return statements in core forms.
- Deprecation trigger in `FormSubmitter::executeSubmitHandlers()` for non-null return values, with unit test in `FormSubmitterTest`.
- Removed all 182 `missingType.return` entries from `core/.phpstan-baseline.php`.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.72 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

keerthi kumar’s picture

Status: Needs work » Needs review
mstrelan’s picture

Status: Needs review » Needs work

Where is the deprecation? We also need a change record.

keerthi kumar’s picture

Status: Needs work » Needs review

Updated MR 17929 and drafted the change record:
- Restored the deprecation trigger in `\Drupal\Core\Form\FormSubmitter::executeSubmitHandlers()` for non-null return values.
- Added unit test coverage in `FormSubmitterTest::testSubmitHandlerReturnValueDeprecation()`.
- Verified PHPCS and PHPStan pass cleanly.
- Drafted the change record: https://www.drupal.org/node/3641504

mstrelan’s picture

Status: Needs review » Needs work

This might need a bit more thought. I did some contrib searches and found quite a few modules that return an AjaxResponse because they also use submitForm as the ajax callback. We might need to propose an alternative in the change record. Maybe they can split the response into a separate callback, or consider switching to HTMX.

larowlan’s picture

As form API maintainer I think it is acceptable to deprecate this and the change record can advise those contrib modules to split up the callback

mstrelan’s picture

Status: Needs work » Needs review

Pushed some simplifications and updated the CR.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new98 bytes

The Needs Review Queue Bot tested this issue. The merge request has merge conflicts and cannot be merged. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mstrelan’s picture

Status: Needs work » Needs review

Rebased, re-baselined.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new98 bytes

The Needs Review Queue Bot tested this issue. The merge request has merge conflicts and cannot be merged. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.