Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 294883

Entity query age(EntityStorageInterface::FIELD_LOAD_REVISION) only gets current revision ID

$
0
0

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

Reference: https://www.drupal.org/core/beta-changes
Issue categoryBug because current behaviour makes no sense.
Issue priorityMajor because functionality is not useful with current implementation.
DisruptionDoes not disrupt core or any known custom module.

Viewing all articles
Browse latest Browse all 294883

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>