Skip to content

Commit

Permalink
Fixed #211
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Apr 25, 2024
1 parent b1acb15 commit 63214f1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Fixed a bug where front-end links included element reference URL fragments. ([#197](https://github.com/craftcms/ckeditor/issues/197))
- Fixed a bug where `resave` commands would replace nested entries with their rendered output in stored CKEditor field values. ([#211](https://github.com/craftcms/ckeditor/issues/211))

## 4.0.3 - 2024-03-28

Expand Down
18 changes: 9 additions & 9 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public function getSettings(): array
*/
public function normalizeValue(mixed $value, ?ElementInterface $element = null): mixed
{
if (!$this->isCpRequest()) {
if (is_string($value) && $this->isSiteRequest()) {
$value = $this->_prepNestedEntriesForDisplay($value, $element?->siteId);
}

Expand Down Expand Up @@ -1047,7 +1047,7 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId
return $value;
}

$isCpRequest = $this->isCpRequest();
$isSiteRequest = $this->isSiteRequest();
$entries = Entry::find()
->id($entryIds)
->siteId($elementSiteId)
Expand All @@ -1063,9 +1063,11 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId
/** @var Entry|null $entry */
$entry = $entries[$entryId] ?? null;

if (!$entry || (!$isCpRequest && $entry->trashed)) {
if (!$entry || ($isSiteRequest && $entry->trashed)) {
$entryHtml = '';
} elseif ($isCpRequest) {
} elseif ($isSiteRequest) {
$entryHtml = $entry->render();
} else {
try {
$entryHtml = $this->getCardHtml($entry);

Expand All @@ -1081,8 +1083,6 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId
// this can happen e.g. when the entry type has been deleted
$entryHtml = '';
}
} else {
$entryHtml = $entry->render();
}

$value = str_replace($marker, $entryHtml, $value);
Expand All @@ -1106,11 +1106,11 @@ private function defaultCreateButtonLabel(): string
]);
}

private function isCpRequest(): bool
private function isSiteRequest(): bool
{
return (
Craft::$app->getRequest()->getIsCpRequest() &&
!Craft::$app->controller instanceof GraphqlController
Craft::$app->getRequest()->getIsSiteRequest() ||
Craft::$app->controller instanceof GraphqlController
);
}

Expand Down

0 comments on commit 63214f1

Please sign in to comment.