[development] Views question

Simon Lindsay simon at dirtbike.ws
Fri Feb 17 03:31:25 UTC 2006


I want to have a selectable field for the views module called "close" 
that executes a function like this:

function job_close() {
   $job = arg(2);
   $sid = 15; // Should be configurable.
   workflow_execute_transition($job, $sid);
   drupal_goto('job/open');
}

I've got it to work using the code below, but its not right. I shouldn't 
have to use a valid field in the 'fields' section. This also means that 
you can't have multiple versions, ie one to "approve", one to "close".

Anybody got any suggestions on a better way?

TIA

function job_views_tables() {
   $tables['job'] = array(
     'name' => 'job',
     'join' => array(
       'left' => array(
         'table' => 'node',
         'field' => 'nid'
       ),
       'right' => array(
         'field' => 'nid'
       )
     ),
     'fields' => array(
       'job_id' => array(
         'name' => t('job: Job Id'),
         'sortable' => TRUE,
       ),
       'cid' => array(
         'name' => t('job: Customer Id'),
         'sortable' => TRUE,
       ),
       'nid' => array(
         'name' => t('job: Close link'),
         'handler' => 'views_handler_field_job_close',
       ),
     ),
     'sorts' => array(
       'job_id' => array('name' => t('Job Id')),
       'cid' => array('name' => t('Customer Id')),
     ),
   );

   return $tables;
}

function views_handler_field_job_close($op, &$query, $argtype, $arg = '') {
   switch ($op) {
   default:
     return l('close', "job/close/$arg->nid");
   }
}




More information about the development mailing list