I made a custom entity with a date field stored as datetime in mysql.

I see the proper output in my content, and all other field values in my views except the datetme value. Only the label is shown. So I believed that I have to write a getter callback because of this:

getter callback: (optional) A callback used to retrieve the value of the property. Defaults to entity_property_verbatim_get(). It is important that your data is represented, as documented for your data type, e.g. a date has to be a timestamp. Thus if necessary, the getter callback has to do the necessary conversion. In case of an empty or not set value, the callback has to return NULL.

Question is how to use it? Apparantly I have to get a timestamp from a datetime field!???

Another one mentioned that views doesn't relate to property_info():

Getter and Setter callbacks are used only by entity metadata wrappers, not Views.

So my code looks like this atm:

$info['pricedefault']['properties']['preis_zeitraum_von'] = array(
'label' => t('Start period'),
'description' => t('Preis Zeitraum von'),
'type' => 'date',
'schema field' => 'preis_zeitraum_von',

So it makes no sense to add a getter callback??? Or do I have to make my own views entity controller class?

ATM I'm very confused. Can anybody explain how to proceed?

THX in advance


1 Answer 1


You won't need to define a custom getter callback for known data types with a schema field since it can use entity_property_verbatim_get as it's getter callback, which is used by default if no 'getter callback' property is set.

$properties = &$info['foo']['properties'];
$properties['created'] = array(
  'label' => t('Date created'),
  'description' => t('The date the foo entity was created.'),
  'type' => 'date',
  'schema field' => 'created',

For maximum control, I would suggest you try describing your entity to views. Assuming you have an entity type called foo, stored in the table foo with a created field, you can:

 * Implements hook_views_data()
function foo_views_data() {
  $data = array();

  $data['foo']['table']['group']  = t('Foo entity');

  $data['foo']['table']['base'] = array(
    'field' => 'foo_id',
    'title' => t('Foo entity'),
    'help' => t('The foo entity.'),
  $data['foo']['table']['entity type'] = 'foo';

  // Expose a timestamp (e.g. created date).
  $data['foo']['created'] = array(
    'title' => t('Created'),
    'help' => t('The date the foo was created.'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    'sort' => array(
      'handler' => 'views_handler_sort_date',
    'filter' => array(
      'handler' => 'views_handler_filter_date',

Then, you can also do things like:

// An argument handler accepting year and month
$data['created']['created_year_month'] = array(
  'title' => t('Created year + month'),
  'help' => t('In the form of YYYYMM.'),
  'argument' => array(
    'field' => 'created',
    'handler' => 'views_handler_argument_node_created_year_month',

For more info on integrating with views, you can install Advanced help module, and check out the included Views documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.