Thanks a lot. I did go down the Views PHP route initially, but it struck me as a bit un-Drupally, and even Views PHP says to use handlers where possible.
In the end I used hook_views_data and did:
function mymodule_views_views_data() {
$data['views']['current_path'] = array(
'title' => t('Current Path'),
'help' => t('Provide current path.'),
'field' => array(
'handler' => 'concept2_views_handler_field_current_path',
),
);
return $data;
}
/**
* Implementation of hook_views_handlers() to register all of the basic handlers
* views uses.
*/
function mymodule_views_views_handlers() {
return array(
'info' => array(
'path' => drupal_get_path('module', 'mymodule') . '/handlers',
),
'handlers' => array(
// The name of my handler
'mymodule_views_handler_field_current_path' => array(
// The name of the handler we are extending.
'parent' => 'views_handler_field',
),
),
);
}
With a handler file like:
/**
* A handler to provide a field that is completely custom by the administrator.
*
* @ingroup views_field_handlers
*/
class mymodule_views_handler_field_current_path extends views_handler_field {
function query() {
// do nothing -- to override the parent query.
}
function option_definition() {
$options = parent::option_definition();
// Override the alter text option to always alter the text.
$options['alter']['contains']['alter_text'] = array('default' => TRUE, 'bool' => TRUE);
$options['hide_alter_empty'] = array('default' => FALSE, 'bool' => TRUE);
return $options;
}
function options_form(&$form, &$form_state) {
parent::options_form($form, $form_state);
unset($form['help']);
}
function render($values) {
// Return the text, so the code never thinks the value is empty.
return drupal_get_path_alias();
}
}