Support from Acquia helps fund testing for Drupal Acquia logo

Comments

yched’s picture

True, 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.

bjaspan’s picture

Version: 8.x-dev » 7.x-dev

I don't see this why is affected by code freeze. We would be doing little more than renaming an internal function.

yched’s picture

Status: Active » Needs review
FileSize
374.34 KB

Here 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.

yched’s picture

Issue tags: +API clean-up
yched’s picture

Oops, forgot to add update.module's new sites/default/private folder to my .cvsignore, lots of unwanted stuff in the previous patch.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Title: Move field_extract_ids() to entity_* namespace » Move entity handling out of Field API
Status: Needs work » Needs review
FileSize
43.02 KB

Many 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) {...} 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.

Let's see where we stand.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
42.75 KB

Race condition with a recent commit, I guess. Rerolled.

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
43.63 KB

field_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.

yched’s picture

Better. Stopping here for tonight. If someone wants to help with the translation-related failures, I won't be sorry ;-)

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Attached 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:

  drupal_static_reset('entity_get_info');
  cache_clear_all('entity_info', 'cache');

After all the drupal_static() frenzy, is that really the official D7 way ? Ew.

yched’s picture

Status: Needs work » Needs review
catch’s picture

There'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).

Status: Needs review » Needs work

The last submitted patch failed testing.

yched’s picture

Status: Needs work » Needs review
FileSize
43.91 KB

Invalid PHP syntax ? Strange, same patch came back green yesterday, and the only change in field.multilingual.inc is:

+++ modules/field/field.multilingual.inc	27 Oct 2009 01:24:21 -0000
@@ -95,7 +95,7 @@
-  $obj_info = field_info_fieldable_types($obj_type);
+  $obj_info = entity_get_info($obj_type);

Reroll, restest.

yched’s picture

Priority: Normal » Critical

Setting 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.

catch’s picture

Status: Needs review » Reviewed & tested by the community

This 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.

Dries’s picture

Status: Reviewed & tested by the community » Fixed

OK, committed to CVS HEAD!

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

yched’s picture