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 |
Issue fork drupal-2525794
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 #1
plachIn #2453175-124: Remove EntityFormInterface::validate() and stop using button-level validation by default in entity forms @Berdir said:
Comment #2
dcmul 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 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
switchinstead of usingifs 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 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 commentedfixing the syntax error
Comment #10
dcmul 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 D11, D10, D9, or D8 and should be removed
Comment #29
andypostComment #30
suresh prabhu parkala commentedJust a re-roll. Please review.
Comment #31
anchal_gupta commentedI have Fixed the custom command failed. Please Review
Comment #32
Ankit.Gupta commentedReroll the patch #30 with Drupal 10.1.x
Comment #33
chi commentedWhy does it apply long array syntax?
In PHP 8 the above code can be written in more readable way using
matchexpression.As a bonus it'll throw an exception when save operation returns unexpected value.
Comment #34
chi commentedAgreed with #26. This issue is too broad and has to be split into sub-tasks.
Comment #35
needs-review-queue-bot 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"
Comment #39
berdirForgot about this issue, see m recent comments in #3264370: Remove return value from EntityFormInterface::save