From 83ab2a89b7b549133d9c7ba6bbb2c127ff272ee5 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Wed, 12 Jun 2024 14:57:46 +0100 Subject: [PATCH 1/3] render nested entries for static html --- src/Field.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index a7d2a16e..fb155e2d 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1046,7 +1046,9 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s $entry = $entries[$chunk->entryId]; try { - if (!$static) { + if ($static) { + return $this->getCardHtml($entry); + } else { return Html::tag('craft-entry', options: [ 'data' => [ 'entry-id' => $entry->isProvisionalDraft ? $entry->getCanonicalId() : $entry->id, From 071c5296d5d194f9d4a914fad48e723d353c8deb Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 12 Jun 2024 08:10:44 -0700 Subject: [PATCH 2/3] Cleanup --- src/Field.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Field.php b/src/Field.php index fb155e2d..2e75a29d 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1046,20 +1046,22 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s $entry = $entries[$chunk->entryId]; try { - if ($static) { - return $this->getCardHtml($entry); - } else { - return Html::tag('craft-entry', options: [ - 'data' => [ - 'entry-id' => $entry->isProvisionalDraft ? $entry->getCanonicalId() : $entry->id, - 'card-html' => $this->getCardHtml($entry), - ], - ]); - } + $cardHtml = $this->getCardHtml($entry); } catch (InvalidConfigException) { // this can happen e.g. when the entry type has been deleted return ''; } + + if ($static) { + return $cardHtml; + } + + return Html::tag('craft-entry', options: [ + 'data' => [ + 'entry-id' => $entry->isProvisionalDraft ? $entry->getCanonicalId() : $entry->id, + 'card-html' => $cardHtml, + ], + ]); }) ->join(''); } From 037758fb3c62cb4d74c5eaf92fe5d9ef1db29dd7 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Wed, 12 Jun 2024 08:10:58 -0700 Subject: [PATCH 3/3] Don't swap in provisional drafts for static fields --- src/Field.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Field.php b/src/Field.php index 2e75a29d..f334f2fe 100644 --- a/src/Field.php +++ b/src/Field.php @@ -1034,7 +1034,10 @@ protected function prepValueForInput($value, ?ElementInterface $element, bool $s ->keyBy(fn(EntryChunk $chunk) => $chunk->entryId) ->map(fn(EntryChunk $chunk) => $chunk->getEntry()) ->all(); - ElementHelper::swapInProvisionalDrafts($entries); + + if (!$static) { + ElementHelper::swapInProvisionalDrafts($entries); + } $value = $chunks ->map(function(BaseChunk $chunk) use ($static, $entries) {