You are here

public function LatestRevision::query in Workbench Moderation 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/views/filter/LatestRevision.php \Drupal\workbench_moderation\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

src/Plugin/views/filter/LatestRevision.php, line 86

Class

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

Namespace

Drupal\workbench_moderation\Plugin\views\filter

Code

public function query() {

  // The table doesn't exist until a moderated node has been saved at least
  // once. Just in case, disable this filter until then. Note that this means
  // the view will still show all revisions, not just latest, but this is
  // sufficiently edge-case-y that it's probably not worth the time to
  // handle more robustly.
  if (!$this->connection
    ->schema()
    ->tableExists('workbench_revision_tracker')) {
    return;
  }
  $table = $this
    ->ensureMyTable();

  /** @var Sql $query */
  $query = $this->query;
  $definition = $this->entityTypeManager
    ->getDefinition($this
    ->getEntityType());
  $keys = $definition
    ->getKeys();
  $definition = [
    'table' => 'workbench_revision_tracker',
    'type' => 'INNER',
    'field' => 'entity_id',
    'left_table' => $table,
    'left_field' => $keys['id'],
    'extra' => [
      [
        'left_field' => $keys['langcode'],
        'field' => 'langcode',
      ],
      [
        'left_field' => $keys['revision'],
        'field' => 'revision_id',
      ],
      [
        'field' => 'entity_type',
        'value' => $this
          ->getEntityType(),
      ],
    ],
  ];
  $join = $this->joinHandler
    ->createInstance('standard', $definition);
  $query
    ->ensureTable('workbench_revision_tracker', $this->relationship, $join);
}