My setup is that I'm using viewsreference as a field in the paragraph and paragraph's parent entity is node.
It doesn't work because can't load entity with this code:
$entity_keys = $entity_storage->getEntityType()->getKeys();
$entities = $entity_storage->loadByProperties([
$entity_keys['id'] => $reload['parent_entity_id'],
$entity_keys['revision'] => $reload['parent_revision_id'],
]);
The issue you're encountering is that loadByProperties() is designed to query only the current/default revision stored in the paragraphs_item_field_data table.
When you are on a page like /node/[nid]/latest, you are likely dealing with a forward revision (a draft or pending revision). In this state, the specific paragraph revision ([revision_id]) may not be the "default" one yet. Consequently, it only exists in the revision tables (paragraphs_item_revision and paragraphs_item_revision_field_data), causing the query to return no results because loadByProperties() does not look there.
The solution:
if (empty($reload['parent_revision_id'])) {
$entity = $entity_storage->load($reload['parent_entity_id']);
}
else {
if ($entity_storage instanceof RevisionableStorageInterface) {
$entity = $entity_storage->loadRevision($reload['parent_revision_id']);
}
else {
// Fallback for non-revisionable entities.
$entity = $entity_storage->load($reload['parent_entity_id']);
}
}Issue fork viewsreference_extras-3573365
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
nnevillComment #6
scott_euser commentedThank you! Fixed up the test coverage, the next major issue was unrelated to this, needs to be disabled for now while we wait for D12 to get broader support