Security update to Drupal 8.4.6
[yaffs-website] / web / core / modules / search / src / Plugin / views / field / Score.php
1 <?php
2
3 namespace Drupal\search\Plugin\views\field;
4
5 use Drupal\views\Plugin\views\field\NumericField;
6 use Drupal\views\ResultRow;
7
8 /**
9  * Field handler for search score.
10  *
11  * @ingroup views_field_handlers
12  *
13  * @ViewsField("search_score")
14  */
15 class Score extends NumericField {
16
17   /**
18    * {@inheritdoc}
19    */
20   public function query() {
21     // Check to see if the search filter added 'score' to the table.
22     // Our filter stores it as $handler->search_score -- and we also
23     // need to check its relationship to make sure that we're using the same
24     // one or obviously this won't work.
25     foreach ($this->view->filter as $handler) {
26       if (isset($handler->search_score) && ($handler->relationship == $this->relationship)) {
27         $this->field_alias = $handler->search_score;
28         $this->tableAlias = $handler->tableAlias;
29         return;
30       }
31     }
32
33     // Hide this field if no search filter is in place.
34     $this->options['exclude'] = TRUE;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function render(ResultRow $values) {
41     // Only render if we exist.
42     if (isset($this->tableAlias)) {
43       return parent::render($values);
44     }
45   }
46
47 }