public function RateSort::query in Rate 8
Called to add the sort to a query.
Overrides SortPluginBase::query
File
- src/
Plugin/ views/ sort/ RateSort.php, line 53
Class
- RateSort
- Basic sort handler for Rates.
Namespace
Drupal\rate\Plugin\views\sortCode
public function query() {
$this
->ensureMyTable();
$id = $this->entityTypeManager
->getDefinition($this->tableAlias)
->get('entity_keys')['id'];
$configuration = [
'table' => 'votingapi_result',
'field' => 'entity_id',
'left_table' => $this->tableAlias . '._field_data',
'left_field' => $this->tableAlias . '.' . $id,
'operator' => '=',
'extra' => [
[
'field' => 'entity_type',
'value' => $this->tableAlias,
],
[
'field' => 'function',
'value' => 'vote_average',
],
],
];
$join = Views::pluginManager('join')
->createInstance('standard', $configuration);
$this->query
->addRelationship('vote', $join, $this->tableAlias . '._field_data');
$this->query
->addOrderBy('vote', 'value', $this->options['order']);
}