Skip to content

Commit

Permalink
Fixed #15777
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Sep 23, 2024
1 parent e8ea576 commit 0e2fa43
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Fixed an error that occurred when running the `entrify/global-set` command. ([#15746](https://github.com/craftcms/cms/issues/15746))
- Fixed a bug where users’ `username` values weren’t getting updated based on email address changes when `useEmailAsUsername` was enabled. ([#15758](https://github.com/craftcms/cms/issues/15758))
- Fixed a bug where the `hasAlt` asset query param wasn’t working properly. ([#15762](https://github.com/craftcms/cms/issues/15762))
- Fixed a bug where relational fields could show related elements for other field instances within element indexes. ([#15777](https://github.com/craftcms/cms/issues/15777))

## 5.4.4 - 2024-09-14

Expand Down
7 changes: 7 additions & 0 deletions src/fields/BaseRelationField.php
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,13 @@ public function getPreviewHtml(mixed $value, ElementInterface $element): string
/** @var ElementQueryInterface|ElementCollection $value */
if ($value instanceof ElementQueryInterface) {
$value = $this->_all($value, $element)->collect();
} else {
// todo: come up with a way to get the normalized field value ignoring the eager-loaded value
$rawValue = $element->getBehavior('customFields')->{$this->handle} ?? null;
if (is_array($rawValue)) {
$ids = array_flip($rawValue);
$value = $value->filter(fn(ElementInterface $element) => isset($ids[$element->id]));
}
}

return $this->previewHtml($value);
Expand Down

0 comments on commit 0e2fa43

Please sign in to comment.