function GroupwiseMax::query
Same name in other branches
- 9 core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php \Drupal\views\Plugin\views\relationship\GroupwiseMax::query()
- 8.9.x core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php \Drupal\views\Plugin\views\relationship\GroupwiseMax::query()
- 10 core/modules/views/src/Plugin/views/relationship/GroupwiseMax.php \Drupal\views\Plugin\views\relationship\GroupwiseMax::query()
Overrides RelationshipPluginBase::query
File
-
core/
modules/ views/ src/ Plugin/ views/ relationship/ GroupwiseMax.php, line 346
Class
- GroupwiseMax
- The relationship handler for groupwise maximum queries.
Namespace
Drupal\views\Plugin\views\relationshipCode
public function query() {
// Figure out what base table this relationship brings to the party.
$table_data = Views::viewsData()->get($this->definition['base']);
$base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field'];
$this->ensureMyTable();
$def = $this->definition;
$def['table'] = $this->definition['base'];
$def['field'] = $base_field;
$def['left_table'] = $this->tableAlias;
$def['left_field'] = $this->field;
$def['adjusted'] = TRUE;
if (!empty($this->options['required'])) {
$def['type'] = 'INNER';
}
if ($this->options['subquery_regenerate']) {
// For testing only, regenerate the subquery each time.
$def['left_query'] = $this->leftQuery($this->options);
}
else {
// Get the stored subquery SQL string.
$cid = 'views_relationship_groupwise_max:' . $this->view->storage
->id() . ':' . $this->view->current_display . ':' . $this->options['id'];
$cache = \Drupal::cache('data')->get($cid);
if (isset($cache->data)) {
$def['left_query'] = $cache->data;
}
else {
$def['left_query'] = $this->leftQuery($this->options);
\Drupal::cache('data')->set($cid, $def['left_query']);
}
}
if (!empty($def['join_id'])) {
$id = $def['join_id'];
}
else {
$id = 'subquery';
}
$join = Views::pluginManager('join')->createInstance($id, $def);
// Use a short alias for this:
$alias = $def['table'] . '_' . $this->table;
$this->alias = $this->query
->addRelationship($alias, $join, $this->definition['base'], $this->relationship);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.