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']);
  }
}
Command icon 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

nnevill created an issue. See original summary.

nnevill’s picture

Status: Active » Needs review

scott_euser made their first commit to this issue’s fork.

  • scott_euser committed 45b77e02 on 1.0.x authored by nnevill
    feat: #3573365 ViewsReferenceExtrasCompressionReload::uncompress() doesn...
scott_euser’s picture

Status: Needs review » Fixed

Thank 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

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.