Не могу создать собственный обработчик для Views2 - PullRequest
0 голосов
/ 11 мая 2011

В основном я хочу создать пользовательский обработчик для десериализации поля БД с именем birthday.

Мне удалось правильно вывести сериализованное поле с использованием поля views_handler_ по умолчанию. К сожалению, когда я пытаюсь создать собственный обработчик, я получаю это сообщение:

Ошибка: обработчик для drappsprofiles> день рождения не существует!

Вот структура файла:

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

вот 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');
(...)

вот 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' => 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);
  }
}

Кажется, что drappsprofiles_handler_field_birthday.inc не читается, хотя я не могу понять, почему.

Любая помощь будет оценена. (Я был вокруг этого в течение 2 недель!)

1 Ответ

1 голос
/ 05 июня 2011

Предполагая, что ваш (...) в .views.inc скрывает код вроде:

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

Что я и предполагаю, так как у вашего поля есть группа, из которой можно выбрать его, чтобы оно могло выглядетьдля отсутствующего обработчика ..

Тогда следующая вещь, на которую нужно обратить внимание, находится в .views.inc в module_views_handlers () {:

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

И, кроме того, я не хочу это говорить, но удаление и переустановка модуля, по-видимому, обновляет последние изменения кода в .views.inc .. Я знаю, что мне приходилось это делать несколько раз, вы, наверное, тоже это заметили.

...