开发者

Drupal 6 views field hanlder for two fields

开发者 https://www.devze.com 2023-02-14 09:37 出处:网络
In my custom module, I\'ve got a table like this: aid| int(10) unsigned message| mediumtext variables | mediumtext

In my custom module, I've got a table like this:

aid       | int(10) unsigned
message   | mediumtext 
variables | mediumtext 

This is similar to the schema for watchdog.

I want expose the message field to views (hook_views_data) but through a handler that translates it with the variables field. Something like this:

t($message, unserialize($variables))

Anyone know how to combine two fields and use a field handler to do this?

Here is my hoo开发者_Python百科k_views_data

/**
 * Implementation of hook_views_data().
 */
function mymodule_views_data() {
  $data['gccsi_activity']['aid'] = array(
    'title' => t('Unique ID'),
    'help' => t('The unique id'),
    'sort' => array(
      'handler' => 'views_handler_sort',
    ),
  );
  $data['gccsi_activity']['message'] = array(
    'title' => t('Message'),
    'help' => t('The message...'),
    'sort' => array(
      'handler' => 'views_handler_sort',
    )
    //here is where I want to create a handler that combines two fields
  );
  return $data;
}

Thanks


If you have implemented hook_views_data you can set the used handler.

$data['table']['column']['id']['field'] = array(
  'handler' => 'yourmodule_handler_field_column',
);

Then you implement hook_views_handlers to register the used handler.

Then you write your handler and do the following steps. Let's assume you have one for message

a) in method construct you do

$this->additional_fields['variables'] = 'variables';

b) in method render do your previous stuff

t($values->{$this->field_alias}, unserialize($values->{$this->aliases['variables']}));

The views advanced help part is a good place to look up some general informations about viewsapi


as far as I know the handler class has to live in it's own file.

0

精彩评论

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

关注公众号