4 * Field handler to provide simple renderer that allows linking to a node.
6 class views_handler_field_search_score
extends views_handler_field_numeric
{
7 function option_definition() {
8 $options = parent
::option_definition();
10 $options['alternate_sort'] = array('default' => '');
11 $options['alternate_order'] = array('default' => 'asc');
16 function options_form(&$form, &$form_state) {
17 $style_options = $this->view
->display_handler
->get_option('style_options');
18 if (isset($style_options['default']) && $style_options['default'] == $this->options
['id']) {
19 $handlers = $this->view
->display_handler
->get_handlers('field');
20 $options = array('' => t('No alternate'));
21 foreach ($handlers as
$id => $handler) {
22 $options[$id] = $handler->ui_name();
25 $form['alternate_sort'] = array(
27 '#title' => t('Alternative sort'),
28 '#description' => t('If no search is performed and this field does not appear, pick an alternative default table sort field.'),
29 '#options' => $options,
30 '#default_value' => $this->options
['alternate_sort'],
33 $form['alternate_order'] = array(
35 '#title' => t('Alternate sort order'),
36 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
37 '#default_value' => $this->options
['alternate_order'],
41 parent
::options_form($form, $form_state);
45 // Check to see if the search filter added 'score' to the table.
46 // Our filter stores it as $handler->search_score -- and we also
47 // need to check its relationship to make sure that we're using the same
48 // one or obviously this won't work.
49 foreach ($this->view
->filter as
$handler) {
50 if (isset($handler->search_score
) && $handler->relationship
== $this->relationship
) {
51 $this->field_alias
= $handler->search_score
;
52 $this->table_alias
= $handler->table_alias
;
57 // Hide this field if no search filter is in place.
58 $this->options
['exclude'] = TRUE
;
59 if (!empty($this->options
['alternate_sort'])) {
60 if (isset($this->view
->style_plugin
->options
['default']) && $this->view
->style_plugin
->options
['default'] == $this->options
['id']) {
61 // Since the style handler initiates fields, we plug these values right into the active handler.
62 $this->view
->style_plugin
->options
['default'] = $this->options
['alternate_sort'];
63 $this->view
->style_plugin
->options
['order'] = $this->options
['alternate_order'];
68 function click_sort($order) {
69 if (isset($this->table_alias
)) {
70 $this->query
->add_orderby(NULL
, NULL
, $order, $this->field_alias
);
74 function render($values) {
75 // Only render if we exist.
76 if (isset($this->table_alias
)) {
77 return parent
::render($values);