I have recently done away with using views php as it is unsafe. I have read a comment by @letharion whereby he mentions that adding a php directive disable_functions = eval
is a good practice to tighten up security.
I have a problem with the views global text field:
- One cannot run php functions on fields
- It is a bit messy to have a lot of the html markup in the database
- It runs the markup through filter_xss (which is good) without giving one the flexibility of expanding on the allowed tags.
I have read this question: Move php in views to moduleMove php in views to module and would like to broaden it a bit.
I have implemented the accepted answer and it works with a slight modification:
custom.module:
function custom_views_api() {
return array(
'api' => 3,
'path' => drupal_get_path('module', 'custom') . '/views',
);
}
function custom_print_my_link($nid, $type){
return $nid . '-' . $type;
}
custom.views.inc:
function custom_views_data() {
$data['node']['custom_stuff'] = array(
'field' => array(
'title' => t('Custom link'),
'help' => t('Provide a custom content link.'),
'handler' => 'views_handler_field_node_custom_stuff',
),
);
return $data;
}
views_handler_field_node_link_custom_stuff:
class views_handler_field_node_custom_stuff extends views_handler_field_node {
function construct() {
parent::construct();
$this->additional_fields['type'] = 'type';
$this->additional_fields['nid'] = 'nid'; // this had to be added !!!
}
function query() {
$this->ensure_my_table();
$this->add_additional_fields();
}
function render($values) {
$type = $this->get_value($values, 'type');
$nid = $this->get_value($values, 'nid');
return custom_print_my_link($nid, $type);
}
};
I have set up the view with two hidden fields (nid and type) that appear before this custom field.
This works perfectly for fields attached to the node table.
My question is: How do I implement it for attached fields, and access the fields across relationships as well?