Problem/Motivation
The following entity query,
$vids = \Drupal::service('entity.query')->get($entity->getEntityTypeId())
->age(EntityStorageInterface::FIELD_LOAD_REVISION)
->sort('revision_id')
->execute();
is expected to return all the revision IDs but it only returns the current revision id.
The final query built by the Query.php is following,
SELECT
FROM
{block_content} base_table
ORDER BY base_table.revision_id ASC
This looks at the base_table not the revision table.
If I have 3 revisions (entity_id = 1) I would expect the result [ 1 => 1, 2 => 1, 3 => 1] but this returns only [3 => 1]
A further repercussion of this behavior is that 'forward revisions' do not work. For example, create node 1, vid 1, set to current revision. Create a new revision of that node (vid 2), but not set to the current revision. Entity query will return empty:
<?php
$nids = \Drupal::entityQuery('node')
->condition('nid', [1], 'IN')
->execute();
?>
Proposed resolution
Change the name of the flag $age to the $allRevisions and add new methods (currentRevision() and allRevisions()) as current behaviour makes no sense. Depending on the value of the $allRevisions flag we are joining on the revision or base table.
Remaining tasks
User interface changes
API changes
Removing method age() as it is Drupal 7 remnant and introducing methods currentRevisions() / allRevisions().
Beta phase evaluation
Issue category | Bug because current behaviour makes no sense. |
---|---|
Issue priority | Major because functionality is not useful with current implementation. |
Disruption | Does not disrupt core or any known custom module. |