Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
Most EntityFormInterface::save()
implementations provide a similar logic, with very small variations.
Proposed resolution
It should be possible to make sure all implementations follow exactly the same pattern and even better factor out the common logic in the parent implementations if/when possible.
Remaining tasks
- Write a patch
- Review it
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#35 | 2525794-nr-bot.txt | 144 bytes | needs-review-queue-bot |
#32 | 2525794-32.patch | 36.29 KB | Ankit.Gupta |
#31 | 2525794-31.patch | 36.34 KB | Anchal_gupta |
#31 | 2525794-30_31.txt | 4.83 KB | Anchal_gupta |
#30 | 2525794-30.patch | 36.29 KB | Suresh Prabhu Parkala |
Comments
Comment #1
plachIn #2453175-124: Remove EntityFormInterface::validate() and stop using button-level validation by default in entity forms @Berdir said:
Comment #2
dcmul CreditAttribution: dcmul as a volunteer commentedThis is my take, not sure I am on the right track. If this is ok, I can work on all the implementations of EntityFormInterface::save()
I have done 2 things,
1. Captured the int value that returned by EntityInterface::save
2. Returned that value at the end of the method. As per the docs
Comment #4
dcmul CreditAttribution: dcmul as a volunteer commentedremoved syntax error
Comment #5
plachThanks, the patch is looking very good, already!
Nice catch :)
To make things more consistent, would it make sense to always use a
switch
instead of usingif
s from time to time?Good point about this: we should not break the interface contract.
Please revert this hunk, the previous code was correct: we are in the user register form, so we are always creating a new user entity. The return value will never indicate an error condition, an exception will be thrown in that case.
One side note: when posting a new patch, an interdiff (a diff between the previous patch and the current one) is welcome because it makes reviewing the changes easier, instead of skimming through the whole patch every time.
Comment #6
dcmul CreditAttribution: dcmul as a volunteer commentedThanks for your review.
The implementations below are pending, their structure is a little bit complex
Drupal\shortcut\Form\SetCustomize::save
Drupal\book\Form\BookOutlineForm::save
Drupal\comment\CommentForm::save
Comment #8
dcmul CreditAttribution: dcmul as a volunteer commentedfixing the syntax error
Comment #10
dcmul CreditAttribution: dcmul as a volunteer commentedHope the tests pass this time.
Comment #12
Mile23Patch doesn't apply to 8.1.x.
Refactoring and/or code changes will have to happen in 8.2.x for a task.
Pretty sure this isn't a novice issue.
Comment #13
kostyashupenkoReroll of #10
Comment #26
mmbkThis is imho a quite important issue and is so long abandoned. I guess this issue addresses too many components so that it is hard to handle. Splitting it into sub tasks might speed up the development here.
I started by creating a subtask for the NodeForm::save() method.
Comment #28
andypostlinking related
- #2030291: Allow actions to postpone saving the modified entity
- #3282744: SAVED_DELETED is not used in D10, D9, or D8 and should be removed
Comment #29
andypostComment #30
Suresh Prabhu Parkala CreditAttribution: Suresh Prabhu Parkala at Specbee commentedJust a re-roll. Please review.
Comment #31
Anchal_gupta CreditAttribution: Anchal_gupta at Srijan | A Material+ Company for Drupal India Association commentedI have Fixed the custom command failed. Please Review
Comment #32
Ankit.Gupta CreditAttribution: Ankit.Gupta at Dotsquares Ltd. commentedReroll the patch #30 with Drupal 10.1.x
Comment #33
Chi CreditAttribution: Chi commentedWhy does it apply long array syntax?
In PHP 8 the above code can be written in more readable way using
match
expression.As a bonus it'll throw an exception when save operation returns unexpected value.
Comment #34
Chi CreditAttribution: Chi commentedAgreed with #26. This issue is too broad and has to be split into sub-tasks.
Comment #35
needs-review-queue-bot CreditAttribution: needs-review-queue-bot as a volunteer commentedThe Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".
Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.
Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.
Comment #36
dpiAdding from #3347670: Fix "Method ::save() should return int but return statement is missing"