From 5fabe41352af126c3bb793102bc72a36bc038a5c Mon Sep 17 00:00:00 2001 From: Mike Decker Date: Fri, 17 Feb 2023 05:02:09 -0800 Subject: [PATCH] HSD8-1416 Fix entity usage link --- src/Plugin/views/field/EntityUsageLink.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/Plugin/views/field/EntityUsageLink.php b/src/Plugin/views/field/EntityUsageLink.php index 8c96a9e..f5065a5 100644 --- a/src/Plugin/views/field/EntityUsageLink.php +++ b/src/Plugin/views/field/EntityUsageLink.php @@ -51,9 +51,10 @@ public function query() { $this->ensureMyTable(); // Add the field. $params = $this->options['group_type'] != 'group' ? ['function' => $this->options['group_type']] : []; - +dpm($params); $this->field_alias = $this->query->addField($this->tableAlias, 'source_type', NULL, $params); $this->field_alias_id = $this->query->addField($this->tableAlias, 'source_id', NULL, $params); + $this->field_alias_vid = $this->query->addField($this->tableAlias, 'source_vid', NULL, $params); $this->addAdditionalFields(); } @@ -63,11 +64,20 @@ public function query() { public function render(ResultRow $values) { $type = $values->{$this->field_alias}; $id = $values->{$this->field_alias_id}; + $vid = $values->{$this->field_alias_vid}; if (!$type || !$id) { - return ''; + return null; + } + if ($vid) { + /** @var \Drupal\Core\Entity\RevisionLogInterface $child */ + $child = $this->entityTypeManager->getStorage($type)->loadRevision($vid); + if (!$child->isLatestRevision()) { + return NULL; + } + } + else { + $child = $this->entityTypeManager->getStorage($type)->load($id); } - - $child = $this->entityTypeManager->getStorage($type)->load($id); $parent = $this->getParent($child); if ($parent->hasLinkTemplate('canonical')) { return $parent->toLink()->toRenderable();