function LatestRevision::query

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

Overrides FilterPluginBase::query

File

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

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.