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.
In RDF module we have the following function
/**
* Implements hook_entity_load().
*/
function rdf_entity_load($entities, $type) {
foreach ($entities as $entity) {
// Extracts the bundle of the entity being loaded.
list($id, $vid, $bundle) = entity_extract_ids($type, $entity);
$entity->rdf_mapping = rdf_mapping_load($type, $bundle);
}
}
We can simplify this now we have propper classed entity objects.
/**
* Implements hook_entity_load().
*/
function rdf_entity_load($entities, $type) {
foreach ($entities as $entity) {
$entity->rdf_mapping = rdf_mapping_load($type, $entity->bundle());
}
}
After removing all the entity_extract_ids() calls we can remove the function.
Comment | File | Size | Author |
---|---|---|---|
#44 | remove-entity-extract-ids-1374030-43-interdiff.txt | 766 bytes | Berdir |
#44 | remove-entity-extract-ids-1374030-43.patch | 60.44 KB | Berdir |
#38 | remove-entity-extract-ids-1374030-38.patch | 60.59 KB | Berdir |
#36 | remove-entity-extract-ids-1374030-36.patch | 56.54 KB | Berdir |
#34 | remove-entity-extract-ids-1374030-34.patch | 52.35 KB | Berdir |
Comments
Comment #1
aspilicious CreditAttribution: aspilicious commentedChanging title
Comment #2
aspilicious CreditAttribution: aspilicious commentedPostponed untill we have revision support
Comment #3
aspilicious CreditAttribution: aspilicious commentedComment #4
sunComment #5
aspilicious CreditAttribution: aspilicious commented1) File isn't a proper entity yet
2) Don' know if I handled vid correctly
3) null should be NULL
BUT I still wanted to make this patch to see what would brake :)
Comment #6
aspilicious CreditAttribution: aspilicious commentedFew comments for future reference
We probably need a vid() funtion like we have with id() and bundle() that way we can reset it to a default we want (for each entity).
When we have a proper revision framework for every entity we just have to change the implementation of these vid() functions. Right?
$entity->id()
15 days to next Drupal core point release.
Comment #7
fagoRight. I remember we left it out revisions for the EntityInterface in the first place. I've created #1612014: Create an interface for revisionable entities for that.
Comment #8
aspilicious CreditAttribution: aspilicious commentedGive it to me!
Comment #9
aspilicious CreditAttribution: aspilicious commentedOk possible that I made a mistake somewhere and this should probably wait after the list into options module move
Comment #11
aspilicious CreditAttribution: aspilicious commentedhmmm
Comment #13
aspilicious CreditAttribution: aspilicious commentedStupid php...
Comment #15
aspilicious CreditAttribution: aspilicious commentedAnother try! =D
Comment #17
aspilicious CreditAttribution: aspilicious commentedARGGGHH kill those stdObject objects...
Comment #18
aspilicious CreditAttribution: aspilicious commentedEntityFieldQuery stuff has this code...
We need that stubentity...
Comment #19
BerdirThis is being discussed in #1551140: Remove stub entities, replace entity_create_stub_entity(), there are two working (although not finished/complete) approaches in there and a long-term proposal for the EFQ part. We need to decide how to continue there.
Comment #20
Berdir#15: 1374030-extract-ids-15.patch queued for re-testing.
Comment #22
aspilicious CreditAttribution: aspilicious commentedLets see how bad this patch is
Comment #25
aspilicious CreditAttribution: aspilicious commentedsecond try
Comment #27
mikeryanTired of looking at that title;).
Comment #28
aspilicious CreditAttribution: aspilicious commentedOk someone else can take this for now. Wont look at this for the next day.
Comment #29
tim.plunkettFatal error: Can't use method return value in write context in core/modules/field/field.api.php on line 1919
I just copied the actual field_sql_storage_field_storage_delete_revision() into hook_field_storage_delete_revision().
Comment #31
BerdirRly? U serious?
Worked around that for now, fixed lots of exceptions because of undefined $id's and added type hints for $entity in field.attach.inc, to easier see more of these weird calls if there are any. Book tests, which previously exploded, pass now, let's see about everything else...
Comment #33
BerdirWorking on this, we'll have to fix the test_entity entity before we can do this but I'm making progress...
Comment #34
BerdirGo testbot, go!
This currently also contains a lot of code that is related to fixing test_entity. I'll extract it into the other issue later, just want to see how far we get with this.
Comment #36
BerdirNext try.
Comment #38
BerdirOk, here we go, this should finally pass.
At this point, the conversion of the whole test_entity stuff and the removal of entity_extract_ids() is kinda mixed up because the former is required for this to pass but then required additional test and code changes on top of what's required here so I hope we can get this in together.
I think this is ready for reviews now.
Comment #39
BerdirI do believe this should be major. #1616930: Fix the field_test entity type is and is now kinda blocked on it and I think we all *really* want entity_extract_ids() to be a thing of the past.
Comment #40
Berdir#1723892: Support for revisions for entity save and delete operations would allow us to remove the custom storage controller code here...
Comment #41
xjmYes please.
Comment #42
sunFinally! Excellent clean-up.
Left-over debugging code?
This patch looks RTBC to me after removing that glitch.
Comment #43
plachGreat clean up!
Minor thing: could we use a variable to avoid calling the methods multiple times?
(I wouldn't even ask if there wasn't @sun's remark above to fix :)
Comment #44
BerdirInteresting, looks like I forgot to fix the hook documentation when I removed that function. (not related to this issue). Need to open an issue about that.
Removed the debug code. I added and removed that like 3 times and forgot it multiple times ;)
@plach: I'm not sure. I personally spent quite some time doing performance tests on Entity::id() and we decided to hardcode it, so it's fast and can be called multiple times. So there isn't a performance reason to do so and if it's just for two times, it's IMHO ok to call it directly. But I'm fine with changing it if others agree.
Updated patch attached. Manual interdiff looks bigger, but I verified that's just because code that I'm changing has been moved around.
Comment #45
BerdirRe-adding lost tag.
Comment #46
plachNo problem let's go ahead with this :)
Comment #47
sunThanks!
Also, I agree with @Berdir - it would be strange to "cache" the property values in local variables, for the sole purpose of avoiding the method calls. Those calls should be lightning fast, so I don't see an issue with that.
Comment #48
plachActually, it wasn't a performance concern, just an esthetic one: in many places we have $id or $bundle holding the values returned by the related methods. I was arguing that having a consistent approach would be nice.
Comment #49
Dries CreditAttribution: Dries commentedNice clean-up. I still think
id()
should begetID()
but we can worry about that later. Committed to 8.x. Thanks.Comment #50
BerdirWow, that was fast. Re-opening for change notice.
Comment #51
BerdirSee: http://drupal.org/node/1724986
Comment #52
aspilicious CreditAttribution: aspilicious commentedI would link to "Entity" base class if thats possible on api.d.o. There they can find all the available methods. The current example doesn't say how to convert $vid or $bundle.
Comment #53
BerdirLinked those methods. I think if you see how id() is called, it's kinda obvious. But I really wanted to show that $entity_type no longer needs to be passed around and how function definitions should be updated, even though that's not directly related.
And yes, all these field methods still receive $entity_type, not sure if we want to do that to the field functions as well or wait for the field API rewrite based on plugins.
Comment #54
tim.plunkettLooks good to me.