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?

CommentFileSizeAuthor
#1 uc_views_shipments.png94.82 KBjpstrikesback

Comments

jpstrikesback’s picture

Category: support » bug
StatusFileSize
new94.82 KB

little 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):

function uc_views_shipments_date_api_fields($field) {
  $values = array(
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
    'sql_type' => DATE_UNIX,
    // Timezone handling options: 'none', 'site', 'date', 'utc'.
    'tz_handling' => 'site',
    // Needed only for dates that use 'date' tz_handling.
    'timezone_field' => '',
    // Needed only for dates that use 'date' tz_handling.
    'offset_field' => '',
    // Array of "table.field" values for related fields that should be
    // loaded automatically in the Views SQL.
    'related_fields' => array(),
    // Granularity of this date field's db data.
    'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
  );
  switch ($field) {
    case 'uc_shipments.ship_date':
      return $values;
  }
}

And in uc_views_shipments.views.inc

/**
 * Implementation of hook_views_data().
 */
function uc_views_shipments_views_data() {
  $data = array();

   // Definitions for uc_shipments
  $data['uc_shipments']['table']['group'] = t('Ubercart shipping');
  //serial
  $data['uc_shipments']['table']['base'] = array(
    'field' => 'sid',
    'title' => t('Ubercart Shipments'),
    'help' => t('Order Shipment Details'),
    'weight' => -10,
  );
  // Add shipping details to uc_views
  $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';
  }
  
  return $data;
}

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)

TS79’s picture

I've exactly the same problem and no idea, how to solve.

patcon’s picture

I 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:

  $data['results_students']['year'] = array(
    'title' => t('Year'),
    'help' => t('The year of the given student\'s result.'),
    'field' => array(
      'handler' => 'views_handler_field_date',
      'click sortable' => TRUE,
    ),
    'filter' => array(
      'handler' => 'date_api_filter_handler',
    ),
  );

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!

patcon’s picture

Yep, just tested it myself, and it works fine. For me, implementing hook_date_api_fields was 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 :)

Anonymous’s picture

subscribing
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.

patcon’s picture

Hmm... 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.

patcon’s picture

Anonymous’s picture

To #7. I saw that issue but I believe the filter is working fine there. Wasn't it just a presentation issue?

patcon’s picture

@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 :)

patcon’s picture

@@JoepH Oh hey, your issue might be HOOK_views_api():

function pastresults_views_api() {
  return array(
    'api' => 2,
    'path' => drupal_get_path('module', 'pastresults'),
  );
}
Anonymous’s picture

Thanks patcon for your support.
That hook is setup. Please explain what you mean in #10.

patcon’s picture

Oh 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)

Anonymous’s picture

But 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...

patcon’s picture

oy. 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.

Anonymous’s picture

no worries

patcon’s picture

Give this one a shot. I've got things working fine now with it:
http://drupal.org/node/636618

damienmckenna’s picture

Status: Active » Closed (won't fix)

Unfortunately 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.