From ff77fe5c742f11e4b3c9ab88903bde076aaf6a16 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Thu, 14 Mar 2024 13:34:09 +0000 Subject: [PATCH 1/3] handle deleted entry type --- src/Field.php | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/Field.php b/src/Field.php index 2d13a402..c0d53a0e 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1057,17 +1057,24 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId $entryId = $entryIds[$i]; /** @var Entry|null $entry */ $entry = $entries[$entryId] ?? null; - if (!$entry) { + + if (!$entry || (!$isCpRequest && $entry->trashed)) { $entryHtml = ''; } elseif ($isCpRequest) { - $entryHtml = $this->getCardHtml($entry); - if (!$static) { - $entryHtml = Html::tag('craft-entry', options: [ - 'data' => [ - 'entry-id' => $entryId, - 'card-html' => $entryHtml, - ], - ]); + try { + $entryHtml = $this->getCardHtml($entry); + + if (!$static) { + $entryHtml = Html::tag('craft-entry', options: [ + 'data' => [ + 'entry-id' => $entryId, + 'card-html' => $entryHtml, + ], + ]); + } + } catch (\Throwable $e) { + // this can happen e.g. when the entry type has been deleted + $entryHtml = ''; } } else { $entryHtml = $entry->render(); From 25baddda1fdb7e3b94887172ef976ee10b6e8893 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 14 Mar 2024 13:53:35 -0700 Subject: [PATCH 2/3] Only catch InvalidConfigException's --- src/Field.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index 8a620921..4f2c1057 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1076,7 +1076,7 @@ private function _prepNestedEntriesForDisplay(string $value, ?int $elementSiteId ], ]); } - } catch (\Throwable $e) { + } catch (InvalidConfigException) { // this can happen e.g. when the entry type has been deleted $entryHtml = ''; } From a5a69884991fed38d422d5d23ff73f934824d53f Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Thu, 14 Mar 2024 13:56:18 -0700 Subject: [PATCH 3/3] Release note --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 606b1036..3b58fee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Release Notes for CKEditor for Craft CMS +## Unreleased + +- Fixed an error that could occur when editing an entry with nested CKEditor entries that used a soft-deleted entry type. ([#191](https://github.com/craftcms/ckeditor/issues/191)) + ## 4.0.0 - 2024-03-14 - CKEditor now requires Craft CMS 5.0.0-beta.7 or later.