Remove return value from EntityFormInterface::save

Created on 14 February 2022, almost 3 years ago
Updated 1 August 2024, 5 months ago

Problem/Motivation

EntityFormInterface::save() is a form submission callback but has a return value. The return value is used to determine if the entity was new or updated, this is sometimes used by child classes. However, this information can be determined by the entity itself. Form submission callbacks should not have return values.

Steps to reproduce

The interface documents a return value but many forms in core do not return values. These are form submission callbacks so by design should not have a return value.

Proposed resolution

Remove return value from EntityFormInterface::save and all children.

Remaining tasks

User interface changes

None

API changes

Remove return value from EntityFormInterface::save

Data model changes

Release notes snippet

Original report

Problem/Motivation

The submit function Drupal\Node\NodeForm::save() does not return a value. According to it's interface it should.
See https://api.drupal.org/api/drupal/core!modules!node!src!NodeForm.php/fun...

Steps to reproduce

Proposed resolution

Save the return code from `$node-save() and pass it back to the caller

๐Ÿ› Bug report
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Node systemย  โ†’

Last updated about 15 hours ago

No maintainer
Created by

๐Ÿ‡ฉ๐Ÿ‡ชGermany mmbk MeiรŸen

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Status changed to Needs work almost 2 years ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request โ†’ as a guide.

    This will need a test case showing the issue.

  • ๐Ÿ‡จ๐Ÿ‡ญSwitzerland berdir Switzerland

    This can't be tested because that return type is bogus. save() is used as a submit callback, submit callbacks have no return value. This was just copied from the Entity save method for no reason. We should instead remove the @return from \Drupal\Core\Entity\EntityFormInterface::save().

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    samit.310@gmail.com โ†’ made their first commit to this issueโ€™s fork.

  • Pipeline finished with Failed
    5 months ago
    Total: 1320s
    #219456
  • Pipeline finished with Failed
    5 months ago
    Total: 180s
    #219480
  • Status changed to Needs review 5 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia samit.310@gmail.com

    I Created a new MR(with new branch) against 11.x, as per my analysis it should be a small 1 to 2 line fix, Please review it,
    It has 1 phpstan error, ideally it should not be there as save() function has {@inheritdoc} comment block.

    Thanks
    Samit K.

  • Status changed to Needs work 5 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    Still needs tests.

  • ๐Ÿ‡ฆ๐Ÿ‡บAustralia acbramley

    Cannot be tested as per #12 I also think this would fall into the bucket of a trivial fix that would be too much effort to test.

    Re the rest of #12 - yes it's sort of bogus, but it is used in places to determine if it was a new or existing entity (as per the doc block).

    Looking through other parts of core, there are many that are missing return values though, so just fixing NodeForm isn't really going to help us much (See CommentForm, CommentTypeForm, ActionFormBase, etc)

    So I agree, we should instead deprecate the return value and remove it entirely at some point.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium dieterholvoet Brussels

    Should the return value from EntityInterface::save also be removed? And if so, should we create a separate issue for that or can we deal with that here?

Production build 0.71.5 2024