function LatestRevision::query

Same name and namespace in other branches
  1. 10 core/modules/views/src/Plugin/views/filter/LatestRevision.php \Drupal\views\Plugin\views\filter\LatestRevision::query()
  2. 9 core/modules/views/src/Plugin/views/filter/LatestRevision.php \Drupal\views\Plugin\views\filter\LatestRevision::query()
  3. 8.9.x core/modules/views/src/Plugin/views/filter/LatestRevision.php \Drupal\views\Plugin\views\filter\LatestRevision::query()

Add this filter to the query.

Due to the nature of fapi, the value and the operator have an unintended level of indirection. You will find them in $this->operator and $this->value respectively.

Overrides FilterPluginBase::query

File

core/modules/views/src/Plugin/views/filter/LatestRevision.php, line 84

Class

LatestRevision
Filter to show only the latest revision of an entity.

Namespace

Drupal\views\Plugin\views\filter

Code

public function query() {
  /** @var \Drupal\views\Plugin\views\query\Sql $query */
  $query = $this->query;
  $query_base_table = $this->relationship ?: $this->view->storage
    ->get('base_table');
  $entity_type = $this->entityTypeManager
    ->getDefinition($this->getEntityType());
  $keys = $entity_type->getKeys();
  $subquery = $query->getConnection()
    ->select($query_base_table, 'base_table');
  $subquery->addExpression("MAX(base_table.{$keys['revision']})", $keys['revision']);
  $subquery->groupBy("base_table.{$keys['id']}");
  $query->addWhere($this->options['group'], "{$query_base_table}.{$keys['revision']}", $subquery, 'IN');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.