I've got a custom entity, with a property defined in hook_entity_property_info as such.
$properties['duration'] = array(
'label' => t('Duration'),
'description' => t('Duration of the video in seconds'),
'type' => 'duration',
'schema field' => 'duration',
);
When this gets exposed to views via EntityDefaultViewsController, the map_from_schema_info method doesn't handle properties of type = duration, so the views handlers are never set.
I can add something like the following, but I'm not sure if this is the way to go or not?
case 'duration':
$return += $description + array(
'field' => array(
'real field' => $views_field_name,
'handler' => 'entity_views_handler_field_duration',
'click sortable' => TRUE,
),
'sort' => array(
'real field' => $views_field_name,
'handler' => 'views_handler_sort',
),
'filter' => array(
'real field' => $views_field_name,
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'real field' => $views_field_name,
'handler' => 'views_handler_argument_numeric',
),
);
break;
To be honest I'm not 100% sure if this is a bug in the module or just a misunderstanding of how things should work.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | entity-fix_duration_handler-1989444-2.patch | 2.77 KB | nuez |
| #1 | entity-fix_duration_handler-1989444-1.patch | 2.05 KB | nuez |
Comments
Comment #1
nuezI bumped into the same issue. It´s not exactly a bug, just some code missing. Your solution almost worked, but caused an error in the option_definition method in the duration class.
Perhaps that´s because the duration handler is a handler that is actually completely defined by entity API. It doesnt have like the other handlers a specific parent class (other than views_handler_field).
Well anyway, I don´t understand exactly why, but removing the bit that calls the EntityFieldHandlerHelper option_definition handler seems to make it work. If this patch makes any sense, I hope it can be submitted so we can start using the duration field in views. Thanks!
Comment #2
nuezAllright, the corrected version:
For some reason the $handler->definition['type'] doesnt exist for the duration handler, it throws an error because it cannot find it. No idea why, to be honest, but instead of removing the extra step in the options_form and options_definition methods in the earlier patch, I added a check if $handler->definition['type'] exists. That seems to work fine.
Comment #3
djdevinTested & working.
Comment #5
fagoThat seems reasonable, thanks committed.