开发者

Can't create custom handler for Views2

Basically I want to create a custom handler to unserialize a db field called birthday.

I've managed to correctly output the field serialized using the default views_handler_field. Unfortunately When I try to create a custom handler, I get this message:

Error: handler for drappsprofiles > birthday doesn't exist!

Here's the file structure:

all/modules/drapps/drappsprofile/
  |->drappsprofiles.views.inc
  |->drappsprofiles.module
  |->drappsprofiles.install
  |->drappsprofiles.info
  |->drappsprofiles.inc
  |->drappsprofiles_handler_field_birthday.inc

here's drappsprofiles.module

/**
 * VIEWS2 MODULE
 * Implementation hook_views_api
 **/
function drappsprofiles_views_api() {
  $info['api'] = 2;
  return $info;
}

/*****************************************************************************
 *                                  INCLUDES
 **/ 
  // Loads Google Apps Profile Integration
  module_load_include('inc', 'drappsprofiles');
(...)

here's drappsprofiles.views.inc

/**
 *
 * Implementation of hook_views_handlers().
 *
 **/
function drappsprofiles_views_handlers() {
  return array(
    'handlers' => array(
      'drappsprofiles_handler_field_birthday' => array(
        'parent' => 'views_handler_field',
      )
    )
  );
}



/**
 * Implementation of hook_views_data().
 *
 * @return array
 **/
function drappsprofiles_views_data() {

(...)
    $data['drappsprofiles']['birthday'] = array(
            'title' => t('Birthday'),
            'help' => t('Users birthday'),
            'field' 开发者_StackOverflow中文版=> array(
                'handler' => 'drappsprofiles_handler_field_birthday',
                'click sortable' => FALSE,
            ),
    );
    return $data;
}

drappsprofiles_handler_field_birthday.inc

<?php
/**
 *
 * Custom views handler for Birthday
 *
 */
class drappsprofiles_handler_field_birthday extends views_handler_field {

  function render($values) {

    $val = unserialize($values->{$this->field_alias});

    return ($val);
  }
}

It seems that drappsprofiles_handler_field_birthday.inc is not being read, although I can't figure out why.

Any help would be appreciated. (I've been around this for 2 weeks!)


Assuming your (...) in .views.inc conceals code like:

  $data['drappsprofiles']['table']['group'] = t('drappsprofiles');
  $data['drappsprofiles']['table']['base'] = array(
     'field' => 'birthday',
     );
  $data['drappsprofiles']['table']['join'] = array(
    '#global' => array(),
  );

Which I am assuming it does since your field has a group from which to select it so that it can look for the missing handler..

Then the next thing to look at is still in .views.inc in module_views_handlers() { :

  return array(
++  'info' => array(
++    'path' => drupal_get_path('module','drappsprofilse'),
++    ),
     'handlers' => array(

And beyond that, I hate to say it, but uninstalling and reinstalling the module apparently refreshes recent code tweaks to the .views.inc .. I know I had to a bunch of times, you probably noticed this too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜