Problem/Motivation
Similary to #2225347: [META] Replace calls to ENTITY_TYPE_load() and ENTITY_TYPE_load_multiple() with static method calls we still have a lot of procedural wrappers around entity related topics.
Proposed resolution
Let's mark the following methods as deprecated for removal in 9.x:
\entity_get_bundles
\entity_load
\entity_revision_load
\entity_revision_delete
\entity_load_multiple_by_properties
\entity_load_unchanged
\entity_delete_multiple
\entity_create
\entity_page_label
\entity_view
\entity_view_multiple
\entity_get_display
\entity_get_form_display
This issue should not remove the functions, nor convert existing calls to them, since that is not an allowed change during the beta.
Beta phase evaluation
| Issue category | Task because there is no functional bug. |
|---|---|
| Issue priority | Normal because, while deprecating these will somewhat improve consistency, testability, and developer experience, it does not have a significant impact. |
| Unfrozen changes | The sole goal of this issue is to document that these procedural functions are deprecated (and what their replacements are), so it is unfrozen during the beta. |
Remaining tasks
- Document the deprecations and replacements for all these functions.
- Create a followup issue (postponed until 8.1.x) to convert existing calls to them to the recommended alternatives.
User interface changes
API changes
| Comment | File | Size | Author |
|---|---|---|---|
| #57 | interdiff-2474151-55-57.txt | 3.82 KB | dcmul |
| #57 | mark_procedural-2474151-57.patch | 12.07 KB | dcmul |
| #55 | interdiff.txt | 5.59 KB | jeroent |
| #55 | mark_procedural-2474151-55.patch | 12.05 KB | jeroent |
| #54 | interdiff.txt | 11.36 KB | jeroent |
Comments
Comment #1
dawehnerComment #2
xjmComment #3
xjmComment #4
tom verhaeghe commentedComment #5
disasm commenteddeprecating methods in entity.inc.
Comment #6
bojanz commentedMarked the old #2135693: Deprecate wrappers in entity.inc as a duplicate.
Comment #7
tom verhaeghe commentedComment #8
rick_p commentedA group of us are working on this (reviewing) at the Drupacon Sprint.
Update: May 15, 2015 at 12:10pm - Patch needs work, the actual status is unclear because there is a mismatch (discrepancy) in the code compared to the issue summary. There is a method (entity_load_multiple) which is commented as deprecated at line 151 in the patch that is not in the issue summary. Is this just scope creep or was that method inadvertently omitted from the issue summary?
Comment #9
rick_p commentedComment #10
rick_p commentedComment #11
mglamanMoving back to needs review. In regards to #8, I believe it was mistakenly left out of issue summary, given this meta issue: #2225347: [META] Replace calls to ENTITY_TYPE_load() and ENTITY_TYPE_load_multiple() with static method calls
Comment #13
dawehnerYeah I left that out on intention, but I'm fine with marking it as deprecated as part of this issue entirely. I mean , being pragmatic about issue dependencies is fine.
Comment #14
xjmThanks folks!
In each case, we need to also document what should be used in place of the function.
Comment #15
chananapeeyush commentedDocumented at all the places.Needs Reviewers Eyes.
Note : At some places the comments has gone beyond 80 chars.So thoughts ?
Comment #16
mile23Needs a reroll.
Comment #17
nitesh sethia commentedRerolled the patch as per D8 latest release.
Comment #18
mile23I'm not sure whether deprecations are still happening, but these make sense, especially given the how-to info in the @deprecated annotation.
Just a couple things:
\Drupal::entityManager()->getStorage($type)->load();
Not sure what's meant here 'by injecting it.' It should just say "Use $entity->label($langcode);"
Comment #19
dcmul commentedThe changes suggested in #18
Comment #20
mile23There's whitespace at the end of the line.
Comment #21
dcmul commentedSo sorry, that was careless. Thanks of the guidance.
Comment #22
tim.plunkettSee the current docs for entity_create(), these methods should reference
and loadMultiple()
Please don't change this.
Comment #23
dcmul commentedThank you, Tim. I have made the changes you suggested in #22
Comment #24
mile23So this should say 8.0.x instead of 8.x-dev... But the usage info should stay the same. :-)
Other than that, RTBC.
Comment #25
dylf commentedMade change and marked RTBC from #24
Comment #26
tim.plunkettThe first half of this patch just says "Use CODE HERE" or has an actual sentence explaining the choices. These last few are not English sentences, and they can probably be removed, and should have the code example
Also, please include an interdiff, and don't RTBC your own patches. Thanks!
Comment #27
sorabh.v6Comment #28
sorabh.v6Patch created on the suggestion of #26. Please review.
Comment #29
jeroentHi @sorabh.v6,
Thank you for your patch. The comments seem already improved, as suggested by @tim.plunkett in #26, but the patch also contains a lot of changes which are not necessary for this issue.
Could you create a new patch that only documents the deprecations? Thanks!
Comment #30
sorabh.v6@JeroenT Sure, I'll do it.
Comment #31
andypoststorage is a handler not a controller
s/render_controller/view_builder
it's not about a render!
Comment #32
jeroentCreated a new patch that contains the changes from patch 28 and the fixes as suggested by andypost in #31.
Interdiff is created from patch 25.
Comment #33
mile23Just a couple coding standards issues:
Wrap at 80.
Wrap at 80.
Comment #34
naveenvalechaRegarding #33.2
$view_builder = \Drupal::entityManager()->getViewBuilder($entity->getEntityTypeId());This should be single line so can't wrap it at 80.
Wrap the text at few other places where I found. Interdiff attached.
Comment #35
naveenvalechaWrap at 80
Comment #36
mile23Looks good and RTBC-ish. Thanks. :-)
However... Is this an unrelated change?
Comment #37
mile23Oops. Also forgot to mention: #2526462: Mark entity_get_bundles() as @deprecated for 9.x. happened already.
Comment #38
naveenvalechaRerolled the patch #34-#38
Comment #39
naveenvalechaThe #37 not automatically merged using git pull.So need reroll
Comment #40
mile23The patch in #39 applies, but you end up with 2 @deprecated blocks for entity_get_bundles(). :-)
Comment #41
sushilkr commentedReRolled.
Comment #42
jeroentComment #44
dcmul commentedI don't think the re-roll on #41 was required since the patch in #38 could apply.
Comment #45
jeroentCreated a new patch that doesn't add 2 deprecated blocks for entity_get_bundles().
Comment #46
jeroentAnd the patch is here!
Comment #47
jeroentCreated a patch that's more in line with the patch in 1 #2526462: Mark entity_get_bundles() as @deprecated for 9.x.
Comment #48
mile23Good deal. Just one thing (in two places):
Colon should come right after 'use,' without any spaces in between.
Comment #49
jeroentFixed feedback in #48.
Comment #50
mile23Woot! Seeing Drupal CI on d.o! :-)
Anyway. Fixes all the stuff, does the deprecation, passes the tests that matter, and I'm sure the other tests are unrelated because this is a docs-only patch.
Comment #51
mile23Comment #52
jeroent@Mile23, I'm sorry, I was too excited so I checked all the tests :p.
Comment #53
xjmThanks everyone. This is looking much improved! Some specific improvements for the current patch:
Here and elsewhere: We should provide @see to
\Drupal\fully\namespaced\Entity::load()and ditto for the storage interface load method, both at the end of the docblock. Reference: https://www.drupal.org/node/1354#seeThat would also allow us to make this a little clearer by saying "The method overriding Entity::load() for the entity type, e.g.
\Drupal\....\Node::load()". Maybe that is clearer; what do you think?We might also want to add @code around the line with the chained method call. Something like:
Oops, missing a - from the ->. :)
It's not actually the entity manager load multiple method. It's the method for the storage. Maybe something like: "Use the entity storage's loadMultiple() and delete() methods to delete multiple entities."
I think there should also be an @see to the \Drupal\fully\namespaced EntityStorageInterface::delete() method (and similarly for loadMultiple()).
Here and elsewhere in the patch: When we have multiple lines in the examples like this, we should use @code/@encode around them so they are formatted properly. Reference: https://www.drupal.org/node/1354#code
I think we can actually remove this paragraph. "Menu title callbacks" aren't a thing anymore and title callbacks can be methods.
This is terse and a bit vague. We should explain it a little more clearly and also include articles and so on (like the word "the") so it's a complete sentence.
Something weird going on with the wording here.
Comment #54
jeroent1-5: Done
6-7: I tried to improve the comments for entity_get_display and entity_get_form_display, but I'm not sure it's completely correct.
Comment #55
jeroentUploaded my patch too fast. Forgot to update the entity_load_multiple_by_properties comment + fixed some indenting problems.
Comment #56
mile23It looks like all the items in #53 are addressed.
Just a few more things...
loadRevision() (add the parentheses).
deleteRevision()
There are a bunch of these. :-)
loadByProperties()
loadUnchanged()
delete()
create()
label()
view()
viewMultiple()
Comment #57
dcmul commented@Mile23, thanks for the reviews.
addressing #56
Comment #58
mile23Cool, thanks. :-)
Comment #59
jeroentComment #60
alexpottCommitted b7fe150 and pushed to 8.0.x. Thanks!