You are here

public function LatestRevision::query in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/src/Plugin/views/filter/LatestRevision.php \Drupal\views\Plugin\views\filter\LatestRevision::query()
  2. 10 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 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();
  $definition = [
    'table' => $query_base_table,
    'type' => 'LEFT',
    'field' => $keys['id'],
    'left_table' => $query_base_table,
    'left_field' => $keys['id'],
    'extra' => [
      [
        'left_field' => $keys['revision'],
        'field' => $keys['revision'],
        'operator' => '>',
      ],
    ],
  ];
  $join = $this->joinHandler
    ->createInstance('standard', $definition);
  $join_table_alias = $query
    ->addTable($query_base_table, $this->relationship, $join);
  $query
    ->addWhere($this->options['group'], "{$join_table_alias}.{$keys['id']}", NULL, 'IS NULL');
}