I have defined a custom field type on a D7 site using the usual suspects (hook_field_info, hook_field_schema, etc.).
The field has two values: 'e164' and 'intl'. I would like to support grabbing these in entity_metadata_wrappers for bundles with instances of this field.
I'm not sure how it does / should work, but I was thinking something like $wrapper->field_name->e164() or $wrapper->field_name->value('e164')... But I'm sure there is some 'plumbing' that needs to be done in my field definition to support this.
None of my documentation browsing has resulted in an answer, surely I'm just missing something!
Comments
Comment #1
obrienmd commentedSigh... I always figure these things out 10 minutes after posting :)
Figured it out by studying addressfield. This is implemented by adding 'property_type' and 'property_callbacks' to the hook_field_info array for the field.
Comment #3
cubeinspire commentedI'm happy to know you solved the issue in only 10 minutes! though it would be much more useful if you also give more details about it :)
Comment #4
kingandyI'm tackling something similar right now. Thanks to @obrienmd for pointing me in the right direction, for the sake of @cubeinspire and anyone else who ends up here via search engine, here's a little more detail...
Looking at addressfield_field_info(), 'property_type' has to be a string and 'property_callbacks' should be an array of function names. These keys are not part of the core hook_field_info functionality, they're extras used by the entity module, documented under entity_hook_field_info().
This passage is the key here:
It's not immediately obvious from this alone (it says to set a value to ... something??) but it becomes clear when going back to the addressfield example, which has simply set 'property_type' to 'addressfield'. I didn't have to dig into the 'property_callbacks' key at all; as soon as I added
'property_type' => 'myfieldtype',to my field_info array it just magically started working. I don't know why entity doesn't assume this to be the case by default, there may be sound technical reasons, but there you go.tl, dr: add
'property_type' => 'myfieldtype',to your hook_field_infoComment #5
kerasai commentedThis type actually should be set per the property types used by the entity module. See
hook_entity_property_info()for these.Setting it to the name of your module may work in some cases, but if it collides with another property type (an entity type, for instance) it will fail or cause unexpected results.