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 voidinFormInterface::submitForm() - Trigger a deprecation in
\Drupal\Core\Form\FormSubmitter::executeSubmitHandlerswhen a submit handler returns a non-null value - Remove redundant return statements from core
submitFormmethods (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
| Comment | File | Size | Author |
|---|
Issue fork drupal-3641402
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
Comment #2
keerthi kumar commentedI would like to work on this!
Comment #4
keerthi kumar commentedI 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`.
Comment #5
needs-review-queue-bot commentedThe 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.
Comment #6
keerthi kumar commentedComment #7
mstrelan commentedWhere is the deprecation? We also need a change record.
Comment #8
keerthi kumar commentedUpdated 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
Comment #9
mstrelan commentedThis might need a bit more thought. I did some contrib searches and found quite a few modules that return an
AjaxResponsebecause they also usesubmitFormas 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.Comment #10
larowlanAs 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
Comment #11
mstrelan commentedPushed some simplifications and updated the CR.
Comment #12
needs-review-queue-bot commentedThe 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.
Comment #13
mstrelan commentedRebased, re-baselined.
Comment #14
needs-review-queue-bot commentedThe 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.