简体   繁体   中英

Drupal 6 views field hanlder for two fields

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 hook_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

据我所知,处理程序类必须存在于它自己的文件中。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM