You are here

function date_entity_metadata_property_info_alter in Date 7

Same name and namespace in other branches
  1. 7.3 date.module \date_entity_metadata_property_info_alter()
  2. 7.2 date.module \date_entity_metadata_property_info_alter()

Callback to alter the property info of date fields.

See also

date_field_info()

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 560

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';
    unset($property['query callback']);
    unset($property['setter callback']);
  }
  if (!empty($field['settings']['todate'])) {

    // Define a simple data structure containing both dates.
    $property['type'] = $field['cardinality'] != 1 ? 'list<struct>' : 'struct';
    $property['getter callback'] = 'entity_metadata_field_verbatim_get';
    $property['property info'] = array(
      'value' => array(
        'type' => 'date',
        'label' => t('From date'),
        'getter callback' => 'date_entity_metadata_struct_getter',
      ),
      'value2' => array(
        'type' => 'date',
        'label' => t('To date'),
        'getter callback' => 'date_entity_metadata_struct_getter',
      ),
      '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',
      ),
    );
    unset($property['query callback']);
    unset($property['setter callback']);
  }
}