I am trying to write some code to handle date fields intelligently no matter what kind of entity they are attached to. To do that I often have to figure out the bundle name so I can retrieve the other information I need. The Field module has a function field_extract_bundle($entity_type, $entity). If you have an entity and know what type of entity it is, that function will tell you the bundle name for the entity. This function works great for all entities except Field Collections. That is because Field Collections does not declare 'bundle keys' as a part of field_collection_entity_info().
The simple addition of the following line to field_collection_entity_info() makes it possible to use field_extract_bundle() to identify the name of the field collection bundle anywhere I have an $entity:
'bundle keys' => array(
'bundle' => 'field_name',
),
Without that bit of code I have to special case every time I check for the name of the bundle to manually see if the entity is a field collection and then manually retrieve the bundle name, since it isn't following any of the rules used by other entities to name its bundles.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | bundle_keys-1263674-4.patch | 441 bytes | azovsky |
| #1 | field_collection-1263674-1.patch | 439 bytes | tim.plunkett |
Comments
Comment #1
tim.plunkettI don't see why not.
Comment #2
fagoIt's the wrong key:
We have no bundle objects. Instead use the 'entity keys', 'bundle' key to extract the bundle + lookup the label from the 'bundles' array.
Comment #3
azovsky commentedThere's still an issue.
Need to add 2 more items for 'entity keys' array:
in field_collection.module in function field_collection_entity_info():
replace:
related with #2020923: Undefined index: label in entity.class.php
Comment #4
azovsky commentedComment #5
jmuzz commentedField collections don't have a title property. There are other issues about supporting custom labels.
Translation support has been added and it didn't require the language key.