/** * {@inheritdoc} */ public function query() { // When there are exposed sorts, the "exposed form" plugin will set // $query->orderby to an empty array. Therefore, if that property is set, // we here remove all previous sorts. // @todo Is this still true in D8? // @todo Check whether #2145547 is still a problem here. if (isset($this->query->orderby)) { unset($this->query->orderby); $sort = &$this->query->getSort(); $sort = array(); } $this->query->sort($this->realField, $this->options['order']); }
/** * {@inheritdoc} */ public function query() { if ($this->operator === 'empty') { $this->query->condition($this->realField, NULL, '=', $this->options['group']); } elseif ($this->operator === 'not empty') { $this->query->condition($this->realField, NULL, '<>', $this->options['group']); } else { while (is_array($this->value)) { $this->value = $this->value ? reset($this->value) : NULL; } if (strlen($this->value) > 0) { $this->query->condition($this->realField, $this->value, $this->operator, $this->options['group']); } } }
/** * {@inheritdoc} */ public function query($group_by = FALSE) { $this->fillValue(); $condition_operator = empty($this->options['not']) ? '=' : '<>'; if (count($this->value) > 1) { $conditions = $this->query->createConditionGroup(Unicode::strtoupper($this->operator)); // $conditions will be NULL if there were errors in the query. if ($conditions) { foreach ($this->value as $value) { $conditions->addCondition($this->realField, $value, $condition_operator); } $this->query->addConditionGroup($conditions); } } else { $this->query->addCondition($this->realField, reset($this->value), $condition_operator); } }
/** * Returns the active search index. * * @return \Drupal\search_api\IndexInterface|null * The search index to use with this filter, or NULL if none could be * loaded. */ protected function getIndex() { if ($this->getQuery()) { return $this->getQuery()->getIndex(); } $base_table = $this->view->storage->get('base_table'); return SearchApiQuery::getIndexFromTable($base_table); }
/** * Retrieves an options list of available fulltext fields. * * @return string[] * An associative array mapping the identifiers of the index's fulltext * fields to their prefixed labels. */ protected function getFulltextFields() { $fields = array(); if (!empty($this->query)) { $index = $this->query->getIndex(); } else { $index = SearchApiQuery::getIndexFromTable($this->table); } if (!$index) { return array(); } $fields_info = $index->getFields(); foreach ($index->getFulltextFields() as $field_id) { $fields[$field_id] = $fields_info[$field_id]->getPrefixedLabel(); } return $fields; }
/** * {@inheritdoc} */ public function query() { if ($this->operator === 'empty') { $this->query->addCondition($this->realField, NULL, '=', $this->options['group']); } elseif ($this->operator === 'not empty') { $this->query->addCondition($this->realField, NULL, '<>', $this->options['group']); } elseif (is_array($this->value)) { $all_of = $this->operator === 'all of'; $operator = $all_of ? '=' : $this->operator; if (count($this->value) == 1) { $this->query->addCondition($this->realField, reset($this->value), $operator, $this->options['group']); } else { $conditions = $this->query->createConditionGroup($operator === '<>' || $all_of ? 'AND' : 'OR'); foreach ($this->value as $value) { $conditions->addCondition($this->realField, $value, $operator); } $this->query->addConditionGroup($conditions, $this->options['group']); } } }
/** * {@inheritdoc} */ public function init(ViewExecutable $view, DisplayPluginBase $display, array &$options = NULL) { parent::init($view, $display, $options); $base_table = $view->storage->get('base_table'); $this->index = SearchApiQuery::getIndexFromTable($base_table, $this->getEntityManager()); if (!$this->index) { throw new \InvalidArgumentException(new FormattableMarkup('View %view is not based on Search API but tries to use its row plugin.', array('%view' => $view->storage->label()))); } }