You are here

public function Snippet::query in Views search snippet 2.x

Same name and namespace in other branches
  1. 8 src/Plugin/views/field/Snippet.php \Drupal\views_search_snippet\Plugin\views\field\Snippet::query()
  2. 1.x src/Plugin/views/field/Snippet.php \Drupal\views_search_snippet\Plugin\views\field\Snippet::query()

Called to add the field to a query.

Overrides FieldPluginBase::query

File

src/Plugin/views/field/Snippet.php, line 25

Class

Snippet
Field handler for search snippet.

Namespace

Drupal\views_search_snippet\Plugin\views\field

Code

public function query() {

  // Check to see if the search filter is present, which we can tell by
  // the 'search_score' property being present. We also need to check its
  // relationship to make sure that we're using the same one or obviously
  // this won't work.
  foreach ($this->view->filter as $handler) {
    if (isset($handler->search_score) && $handler->relationship == $this->relationship) {
      $this->searchFilterPresent = TRUE;
      $this
        ->ensureMyTable();

      // We need the langcode field from the search index table.
      $this->tableAlias = $handler->tableAlias;
      $this->field_alias = $this->query
        ->addField($this->tableAlias, 'langcode', NULL, array());
      return;
    }
  }

  // Hide this field if no search filter is in place.
  $this->options['exclude'] = TRUE;
}