If I expose a db field to views and the views_handler_filter_date can see and filter on it, shouldn't date_api_filter_handler be able to see it? are there other requirements like it must be a field in the base table? The current way I've done it is added the following to uc_views.views.inc (part of the ubercart views module) it's strange to me cause there are other fields (in the base table) exposed to the date_api in the same way and they work fantastically but mine while it certainly uses the handler, it cannot see the actual field so in the list of fields I can filter on, my new field is missing...
// Add shipping details to uc_views
$data['uc_shipments']['table']['group'] = t('Ubercart shipping');
$data['uc_shipments']['table']['join']['uc_orders'] = array(
'left_field' => 'order_id',
'field' => 'order_id',
);
$data['uc_shipments']['sid'] = array(
'title' => t('Order Shipment ID'),
'help' => t('The shipment id.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
);
$data['uc_shipments']['carrier'] = array(
'title' => t('Shipping Carrier Title'),
'help' => t('The shipping carrier used.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
);
$data['uc_shipments']['cost'] = array(
'title' => t('Shipping Cost Amount'),
'help' => t('The shipping actual cost.'),
'field' => array(
'handler' => 'uc_views_handler_field_money_amount',
'click sortable' => TRUE,
),
);
$data['uc_shipments']['ship_date'] = array(
'title' => t('Order Ship Date'),
'help' => t('The shipment date.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
//if the sleeker date module is installed use that for filtering
if(module_exists('date_api')) {
$data['uc_shipments']['ship_date']['filter']['handler'] = 'date_api_filter_handler';
}
Anyone know what I'm doing wrong?
Comments
Comment #1
jpstrikesback commentedlittle update,
I tried it all in it's own module using hook_date_api_fields() and the code above (and adding uc_shipments as the base table) and there is no difference...it seems I'm really missing something or there is a slight bug...the field I'm working with here is uc_shipments.ship_date (courtesy of ubercart) which is a UNIX timestamp. my hook_date_api_fields() looks like this (note: i've tried without the switch):
And in uc_views_shipments.views.inc
Again, it is available as a filter, uses the date api filter handler but the field is not listed in the "filter by" fields (see attached)
Comment #2
TS79 commentedI've exactly the same problem and no idea, how to solve.
Comment #3
patcon commentedI think I solved this somewhere along the line for a custom table I created... trying to learn how to do it again...
I think it was as simple as using this format:
I think date_api only does it automatically for core fields.
If you do things this way, I think that your fields will need to be in the format that Date API recognizes and used to store cck (2010-01-01T00:00:00), but I can't be sure about this... it's just what I use :)
(For whatever reason, I believe that date FIELDS are automatically handled by Date API using the general date field handler (like I used above))
Anyhow, hopefully this helps!
Comment #4
patcon commentedYep, just tested it myself, and it works fine. For me, implementing
hook_date_api_fieldswas the tough part, but since you're done that, just swap in the correct handler, and you'll see all the settings just fine when you add the filter.If you messed up with
hook_date_api_fields, then you'll see the settings, but your field won't show up in the list of checkboxes under the date filter settings. but it looks like you've got it right :)Comment #5
Anonymous (not verified) commentedsubscribing
Facing the same problem, hook_date_api_fields() does not fire.
I digged into a bit deeper and here is what I have found.
Date api has a function date_api_views_fetch_fields() to get all the views fields through views_fetch_fields().
This last function just does not return my custom date field.
Comment #6
patcon commentedHmm... same here: #780192: hook_date_api_fields() is not fired (converted from a support request. see first comment)
I seem to remember having this problem before... and I think there was just a defining function that I was missing. I'm at home, but I'll dig into it tomorrow.
Comment #7
patcon commentedScratch that... never solved it:
#479996: views_handler_field_date for custom module outputs as if default UNIX date type (everything's 1969)
Comment #8
Anonymous (not verified) commentedTo #7. I saw that issue but I believe the filter is working fine there. Wasn't it just a presentation issue?
Comment #9
patcon commented@JoepH, in the last line of comment #2, this issue is dealing with a scenario in which the filter works, but field doesn't display correctly. If yours in completely broken, then you're in the wrong issue thread, and it's probably something that could be resolved with the documentation in Advanced Help for views :)
Comment #10
patcon commented@@JoepH Oh hey, your issue might be HOOK_views_api():
Comment #11
Anonymous (not verified) commentedThanks patcon for your support.
That hook is setup. Please explain what you mean in #10.
Comment #12
patcon commentedOh rat. OK, nevermind -- just thought it may have been left out. You should probably post your custom module code in a new queue, and you might get some helpful feedback from folks. Like I said, I believe it's a separate issue if your filter handler ISN'T working. (This issue deals with a case where the filter is working, but field isn't)
Comment #13
Anonymous (not verified) commentedBut the title "date_api_filter_handler can't find what views_handler_filter_date can see" of this issue is exactly the issue I am facing...
Comment #14
patcon commentedoy. I was clearly in the issue queues much too late at night. My bad. Sorry JoepH. I mixed up the jists of two similar threads.
Comment #15
Anonymous (not verified) commentedno worries
Comment #16
patcon commentedGive this one a shot. I've got things working fine now with it:
http://drupal.org/node/636618
Comment #17
damienmckennaUnfortunately the Drupal 6 version of the Date module is no longer supported. That said, we appreciate that you took time to work on this issue. Should this request still be relevant for Drupal 7 please feel free to reopen it. Thank you.