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.
http://api.drupal.org/api/function/field_extract_ids/7
Should use entity_get_info() and itself be moved to the entity namespace. I realised this when reviewing #493030: RDF #1: core RDF module but it's too late to do this in D7 now.
Comment | File | Size | Author |
---|---|---|---|
#18 | field_entity_info-606994-18.patch | 43.91 KB | yched |
#14 | field_entity_info-606994-13.patch | 43.91 KB | yched |
#11 | field_entity_info-606994-11.patch | 43.63 KB | yched |
#9 | field_entity_info-606994-9.patch | 42.75 KB | yched |
#7 | field_entity_info-606994-7.patch | 43.02 KB | yched |
Comments
Comment #1
yched CreditAttribution: yched commentedTrue, since RDF uses this (and the notion of 'bundles', even though the term was originally intended as 'the collection of fields that a given object has'), outside field stuff, field_extract_ids() belongs to the upper 'entity' level. We would have put it there if the entity API existed when Field API landed.
Given that the function is currently mainly used internally in field.attach.inc (and in the newly committed RDF code), I'd even advocate for doing the switch in D7, but I probably won't fight over this.
Comment #2
bjaspan CreditAttribution: bjaspan commentedI don't see this why is affected by code freeze. We would be doing little more than renaming an internal function.
Comment #3
yched CreditAttribution: yched commentedHere we go. Straight rename of field_extract_ids() and it's counterpart field_create_stub_entity() into the entity_* namespace and common.inc.
A couple whitespace fixes might have sneaked in.
Comment #4
yched CreditAttribution: yched commentedComment #5
yched CreditAttribution: yched commentedOops, forgot to add update.module's new sites/default/private folder to my .cvsignore, lots of unwanted stuff in the previous patch.
Comment #7
yched CreditAttribution: yched commentedMany failures/exceptions because entity_get_info() and field_info_fieldable_types() didn't behave exactly the same way (the field_info version added some more default values).
Updated patch, changed issue title to reflect the new scope:
- fixes this other TODO/WTF where entity info were collected and cached (statically + persistently) in two places: entity_get_info() and in _field_info_collate_types().
_field_info_collate_types() does not collect entity info anymore. field_info_fieldable_types() is gone, entity_get_info() is the only source for entity info.
The only difference is of course that the caller might need to check whether the type is actually fieldable. That's actually fairly rare (in the patch, only field_ui had to change
foreach(field_info_fieldable_types() as $info) {...}
toforeach(entity_get_info() as $info) {if ($info['fieldable']) {...}}
- makes entity_get_info fill in the same default values that _field_info_collate_types() did.
Let's see where we stand.
Comment #9
yched CreditAttribution: yched commentedRace condition with a recent commit, I guess. Rerolled.
Comment #11
yched CreditAttribution: yched commentedfield_info_bundles() directly adressed _field_info_collate_types()'s 'fieldable types' list instead of calling field_info_fieldable_types(), and thus was broken in the previous patch.
Comment #12
yched CreditAttribution: yched commentedBetter. Stopping here for tonight. If someone wants to help with the translation-related failures, I won't be sorry ;-)
Comment #14
yched CreditAttribution: yched commentedAttached patch should take care of the remaining failures.
The RDF failure brought an interesting case:
I won't delve in the details, but the removal of the duplicate 'entity types registry' in _field_info_collate_types() brought a race condition because the entity_get_info() cache wasn't refreshed after the creation of a new content type, resulting in RDF mappings for the new type not being applied..
For now, I fixed that by clearing the entity_get_info() cache inside field_info_cache_clear().
What this outlines though, is that the 'bundle management' functions, field_attach_[create|rename|delete]_bundle() and associated hooks, *also* belong to the entity_* namespace. Bundles are exposed in hook_entity_info(), the notification functions should also be within entity API. It's entity_create_bundle() that should take care of cleaning the entity_get_info() cache.
I preferred not to go there in the current patch because if the current code in field_attach_[create|rename|delete]_bundle() is moved to field.module's implementation of hook_entity_[create|rename|delete]_bundle(), then we lose the guarantee that it's run *before* field storage modules' own [create|rename|delete]_bundle() code, and we enter system.weight hell - meaning we might need both hook_entity_[op]_bundle() and hook_field_[op]_bundle() hooks.
This is better dealt with in a separate issue, let's fix the 'duplicate entity registry' first.
BTW, I'm a little perplexed that there's no API way to clear the cached entity info. Currently all code that wants to rebuild that info needs to know there are both a static and persistent cache and do:
After all the drupal_static() frenzy, is that really the official D7 way ? Ew.
Comment #15
yched CreditAttribution: yched commentedComment #16
catchThere's an open issue somewhere about standardizing static resets in core, because the drupal_static_reset() conversion was very inconsistently applied and we currently lack standards - some functions still have $reset arguments (specifically requested by Dries), some use drupal_static_reset() directly, some have function_name_reset() helpers to reset the cache and in some cases cache_clear_all() too.
Makes sense to leave the various _attach() for now. Haven't looked through the patch, but IMO this will solve some critical wtfs in new D7 APIs, and it's likely no contrib modules are using these yet (fairly easy to grep though).
Comment #18
yched CreditAttribution: yched commentedInvalid PHP syntax ? Strange, same patch came back green yesterday, and the only change in field.multilingual.inc is:
Reroll, restest.
Comment #19
yched CreditAttribution: yched commentedSetting to critical (I thought I did it already). More than the entity_* namespace thing, the scope of this issue is now getting rid of the duplicate 'entity info' registry, which is IMO a major WTF waiting to explode.
Summary:
- moves field_extract_ids() and it's counterpart field_create_stub_entity() into common.inc and the entity_* namespace.
- fixes entity info being collected and cached (statically + persistently) in two places: entity_get_info() and _field_info_collate_types(). This is actually a clean-up after the 'entity loading' patch.
_field_info_collate_types() does not collect entity info anymore. field_info_fieldable_types() is gone, entity_get_info() is the only source for entity info.
The only difference is of course that the caller might need to check whether the type is actually fieldable. That's actually fairly rare (in the patch, only field_ui had to change foreach(field_info_fieldable_types() as $info) {...} to foreach(entity_get_info() as $info) {if ($info['fieldable']) {...}}
- makes entity_get_info() fill in the same default values that _field_info_collate_types() did.
Comment #20
catchThis is really, really nice cleanup. The dual caching meant a duplicate cache hit on each page, and weird synchronization issues between the slightly different array structures returned by entity_get_info() and field_info_fieldable_types(). As can been seen from the patch these are currently still functions used internally within field API, so shouldn't have any effect on modules which are porting - and more importantly won't introduce a huge wtf for modules when they do port.
Comment #21
Dries CreditAttribution: Dries commentedOK, committed to CVS HEAD!
Comment #23
yched CreditAttribution: yched commentedFollowup to #14 - #16: #642612: No clean way to reset entity_info cache