Posted by matslats on January 31, 2013 at 3:34pm
Hi,
I've created a fieldAPI field, but since I installed entity module and defined the properties, I'm unable to render the token for that field.
So $50 to whoever can help me get the token to work.
This is all the relevant code I think
/*
* Implements hook_field_info();
*/
function mcapi_field_info() {
return array(
//oops the field type has the same name as the default_formatter
'worth_field' => array(
'label' => t('Worth'),
'description' => t("One or more values, each denominated in a currency"),
'default_widget' => 'worths_widget',
'default_formatter' => 'worth_field',
'translatable' => FALSE,
//following properties are for the entity API module.
'property_type' => 'worth', //not to be confused with $property['type'], below
'property_callbacks' => array('entity_metadata_field_worth_property_callback'),
)
);
}
//this is a property callback for the worth field in mcapi_field_info
function entity_metadata_field_worth_property_callback(&$info, $entity_type, $field, $instance, $field_type) {
$property = &$info[$entity_type]['bundles'][$instance['bundle']]['properties'][$field['field_name']];
//overwrite some defaults
$property['type'] = 'struct';//this could be the culprit if it was wrong
$property['getter callback'] = 'worth_getter';
$property['setter callback'] = 'worth_setter';
$property['property info'] = entity_property_field_item_worth_info();
}
/*
* PROPERTY_TYPE is referenced in hook_field_info
* is there a hook entity_property_PROPERT_TYPE_info() if so I've not seen it called or documented.
* these correspond to the two columns in the fieldAPI table
*/
function entity_property_field_item_worth_info() {
return array(
'currcode' => array(
'type' => 'text',
'label' => t('Currency code'),
'required' => TRUE,
),
'quantity' => array(
'type' => 'decimal',
'label' => t('Quantity'),
'required' => TRUE,
),
);
}
/**
* Implements hook_field_schema().
* could something be missing here?
*/
function mcapi_field_schema($field) {
if ($field['type'] == 'worth_field') {
return array(
'columns' => array(
'currcode' => array(
'description' => 'The currency ID',
'type' => 'varchar',
'length' => '8',
),
'quantity' => array(
'description' => 'Price',
'type' => 'numeric',
'size' => 'normal',
'precision' => 8,
'scale' => 2
)
)
);
}
}
/*
* This getter function WORKS when called,
* entity_token_tokens instead returns a (string) of its $wrapper object which reads 'Property worth'
*/
function worth_getter($entity, array $options, $property_name, $entity_type, $info) {
return "BLABLAH";
}