function date_entity_metadata_property_info_alter in Date 7.3
Same name and namespace in other branches
- 7 date.module \date_entity_metadata_property_info_alter()
- 7.2 date.module \date_entity_metadata_property_info_alter()
Callback to alter the property info of date fields.
See also
1 string reference to 'date_entity_metadata_property_info_alter'
- date_field_info in ./
date.field.inc - Implements hook_field_info().
File
- ./
date.module, line 597
Code
function date_entity_metadata_property_info_alter(&$info, $entity_type, $field, $instance, $field_type) {
$name = $field['field_name'];
$property =& $info[$entity_type]['bundles'][$instance['bundle']]['properties'][$name];
if ($field['type'] != 'datestamp' || $field['settings']['timezone_db'] != 'UTC') {
// Add a getter callback to convert the date into the right format.
$property['getter callback'] = 'date_entity_metadata_field_getter';
$property['setter callback'] = 'date_entity_metadata_field_setter';
unset($property['query callback']);
}
if (!empty($field['settings']['todate'])) {
// Define a simple data structure containing both dates.
$property['type'] = $field['cardinality'] != 1 ? 'list<struct>' : 'struct';
$property['auto creation'] = 'date_entity_metadata_struct_create';
$property['getter callback'] = 'entity_metadata_field_verbatim_get';
$property['setter callback'] = 'entity_metadata_field_verbatim_set';
$property['property info'] = array(
'value' => array(
'type' => 'date',
'label' => t('Start date'),
'getter callback' => 'date_entity_metadata_struct_getter',
'setter callback' => 'date_entity_metadata_struct_setter',
// The getter and setter callbacks for 'value' and 'value2'
// will not provide the field name as $name, we'll add it to $info.
'field_name' => $field['field_name'],
// Alert Microdata module that this value can be exposed in microdata.
'microdata' => TRUE,
),
'value2' => array(
'type' => 'date',
'label' => t('End date'),
'getter callback' => 'date_entity_metadata_struct_getter',
'setter callback' => 'date_entity_metadata_struct_setter',
// The getter and setter callbacks for 'value' and 'value2'
// will not provide the field name as $name, we'll add it to $info.
'field_name' => $field['field_name'],
// Alert Microdata module that this value can be exposed in microdata.
'microdata' => TRUE,
),
'duration' => array(
'type' => 'duration',
'label' => t('Duration'),
'desription' => t('The duration of the time period given by the dates.'),
'getter callback' => 'date_entity_metadata_duration_getter',
// No setter callback for duration.
// The getter callback for duration will not provide the field name
// as $name, we'll add it to $info.
'field_name' => $field['field_name'],
),
);
unset($property['query callback']);
}
else {
// If this doesn't have a todate, it is handled as a date rather than a
// struct. Enable microdata on the field itself rather than the properties.
$property['microdata'] = TRUE;
}
}