5 * Definition of views_handler_field_search_score.
9 * Field handler to provide simple renderer that allows linking to a node.
11 * @ingroup views_field_handlers
13 class views_handler_field_search_score extends views_handler_field_numeric {
14 function option_definition() {
15 $options = parent::option_definition();
17 $options['alternate_sort'] = array('default' => '');
18 $options['alternate_order'] = array('default' => 'asc');
23 function options_form(&$form, &$form_state) {
24 $style_options = $this->view->display_handler->get_option('style_options');
25 if (isset($style_options['default']) && $style_options['default'] == $this->options['id']) {
26 $handlers = $this->view->display_handler->get_handlers('field');
27 $options = array('' => t('No alternate'));
28 foreach ($handlers as $id => $handler) {
29 $options[$id] = $handler->ui_name();
32 $form['alternate_sort'] = array(
34 '#title' => t('Alternative sort'),
35 '#description' => t('Pick an alternative default table sort field to use when the search score field is unavailable.'),
36 '#options' => $options,
37 '#default_value' => $this->options['alternate_sort'],
40 $form['alternate_order'] = array(
42 '#title' => t('Alternate sort order'),
43 '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')),
44 '#default_value' => $this->options['alternate_order'],
48 parent::options_form($form, $form_state);
52 // Check to see if the search filter added 'score' to the table.
53 // Our filter stores it as $handler->search_score -- and we also
54 // need to check its relationship to make sure that we're using the same
55 // one or obviously this won't work.
56 foreach ($this->view->filter as $handler) {
57 if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
58 $this->field_alias = $handler->search_score;
59 $this->table_alias = $handler->table_alias;
64 // Hide this field if no search filter is in place.
65 $this->options['exclude'] = TRUE;
66 if (!empty($this->options['alternate_sort'])) {
67 if (isset($this->view->style_plugin->options['default']) && $this->view->style_plugin->options['default'] == $this->options['id']) {
68 // Since the style handler initiates fields, we plug these values right into the active handler.
69 $this->view->style_plugin->options['default'] = $this->options['alternate_sort'];
70 $this->view->style_plugin->options['order'] = $this->options['alternate_order'];
75 function render($values) {
76 // Only render if we exist.
77 if (isset($this->table_alias)) {
78 return parent::render($values);