Hi there,

Maybe I'm missing something, but I thought that when Date API was enabled, it took over in any places where the core date views handlers were traditionally used. In the "Configure views" settings, I'm trying to use the date handlers (views_handler_filter_date, etc.), but I'm only getting the oldschool date filter settings in views.

Did the Data module take any shortcuts that might lead to a hook not being called when retrieving handlers? If I understand correctly, these should be replaced automatically, right? Or is it that Data needs to detect when Date API is installed, and offer date_api_filter_handler as an option on the "Configure views" tab of the Data table admin section?

Any insight would be helpful! Thanks

Comments

patcon’s picture

Title: Date API handlers not used » Views handlers on "Configure views" page are hard-coded
Version: 6.x-1.0-alpha9 » 6.x-1.0-alpha14
Category: bug » task

Think I figured out the fix: Seems the default handlers are hard-corded into the data_get_views_handler_options function of data.views.inc:

function data_get_views_handler_options($type = NULL, $reset = FALSE) {
  static $handlers;
  if (!isset($handlers) || $reset) {
    $handlers = array();
    $handlers['field'] = array(
      'views_handler_field' => 'views_handler_field',
      'views_handler_field_numeric' => 'views_handler_field_numeric',
      'views_handler_field_date' => 'views_handler_field_date',
      'views_handler_field_url' => 'views_handler_field_url',
      'views_handler_field_data_markup' => 'views_handler_field_data_markup',
    );
    $handlers['filter'] = array(
      'views_handler_filter_date' => 'views_handler_filter_date',
      'views_handler_filter_float' => 'views_handler_filter_float',
      'views_handler_filter_numeric' => 'views_handler_filter_numeric',
      'views_handler_filter_string' => 'views_handler_filter_string',
    );
    $handlers['argument'] = array(
      'views_handler_argument' => 'views_handler_argument',
      'views_handler_argument_date' => 'views_handler_argument_date',
      'views_handler_argument_numeric' => 'views_handler_argument_numeric',
      'views_handler_argument_string' => 'views_handler_argument_string',
    );
    $handlers['sort'] = array(
      'views_handler_sort' => 'views_handler_sort',
      'views_handler_sort_date' => 'views_handler_sort_date',
    );
    // Allow other modules to alter the list of available handlers.
    drupal_alter('data_views_handlers', $handlers);
  }
  return isset($type) && isset($handlers[$type]) ? $handlers[$type] : $handlers;
}

Any reason why views_discover_handlers can't be used to populate the dropdown selections?
http://api.zzolo.org/api/function/views_discover_handlers/drupal-6

It returns a lump-sum array of all handlers available, but if I understand correctly, all filter/sort/field/argument handlers have their type as part of the machine-code name, right? Shouldn't be hard to list them correctly, right?

Anyone have thoughts?

patcon’s picture

Oh, and apparently that discover function isn't going to be around for D7, but I wasn't sure what would replace it, so I started this issue:
#950020: How to get an array of all handlers

patcon’s picture

Status: Active » Needs review

Alright, so I just realized that this still doesn't solve my date api handler issue (because date_api_filter_handle isn't discovered by views_discover_handlers), but this still gives more handler options, so I can't see why it wouldn't be included (unless my code is too sloppy?)

function data_get_views_handler_options($type = NULL, $reset = FALSE) {
  static $handlers;
  if (!isset($handlers) || $reset) {
    $handlers = array();
    module_load_include('inc', 'views', 'includes/base');
    module_load_include('inc', 'views', 'includes/handlers');
    $available_handlers = views_discover_handlers();
    $handlers = array(
      'field',
      'filter',
      'argument',
      'sort',
    );
    foreach ($available_handlers as $available_handler => $def) {
      foreach($handlers as $handler) {
        $pattern = '/^views_handler_';
        $pattern .= $handler;
        $pattern .= '([_][^_.]+)*$/';
        if (preg_match($pattern, $available_handler)) {
          $handlers[$handler][$available_handler] = $available_handler;
        };
      };
    };
    // Allow other modules to alter the list of available handlers.
    drupal_alter('data_views_handlers', $handlers);
  }
  return isset($type) && isset($handlers[$type]) ? $handlers[$type] : $handlers;
}
patcon’s picture

Mhen... drupal_alter it is. I figured there must've been a way to find all handlers automatically, but this isn't worth the effort.

Anyone willing to review what I have above anyhow? I think it's still a step above what's there now.

patcon’s picture

Alright, so technically, it seems that views_discover_handlers() should find any handler that's been registered with hook_views_handlers(), and date_api_views_handlers() was declared in date_api.views.inc.

But for some reason it's only returning the core handlers... any thoughts?

patcon’s picture

StatusFileSize
new2.56 KB

Alright, so maybe this is going to explode d.o, but here goes: MY. VERY. FIRST. PATCH.

Spent a few days figuring out git and getting it going, so hopefully this works. Let me know if it's in the wrong format or something.

Cheers.

patcon’s picture

StatusFileSize
new2.19 KB

Sorry, used git format-patch instead of git diff.

skylord’s picture

It works. At least generic handlers like 'in_operator' and 'many_to_one' can be selected easily without altering 'data_get_views_handler_options'...

joachim’s picture

Category: task » feature
StatusFileSize
new5.83 KB

Here's the patch for D7.

- need to alter in our own handler because hook_views_handlers() has gone.
- replacement for views_discover_handlers(), until/if something gets added to Views at #950020: How to get an array of all handlers.
- added a notice to the form as it's now quite possible to pick a handler that doesn't work properly because it's not getting data it expects.

joachim’s picture

Status: Needs review » Patch (to be ported)

Committed to D7:

- #948426 by patcon, joachim: Added ability to pick any Views handler for data table fields.

Needs backporting now.

If anyone has time to reroll #7 with my extra form notice that would be a big help :)

joachim’s picture

Version: 6.x-1.0-alpha14 » 6.x-1.x-dev
Status: Patch (to be ported) » Fixed

Committed a rerolled version of #7 to the 6.x-1.x branch.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.