diff --git a/CHANGELOG.md b/CHANGELOG.md index 508e35a0..886453be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ ### Added - Added the ability to track eager-loaded relation fields nested inside matrix blocks ([#657](https://github.com/putyourlightson/craft-blitz/issues/657)). +- Added statuses and edit links to elements displayed in the Blitz Diagnostics utility. ## 4.20.0 - 2024-07-22 diff --git a/src/helpers/DiagnosticsHelper.php b/src/helpers/DiagnosticsHelper.php index a7f3de03..2c0103f3 100644 --- a/src/helpers/DiagnosticsHelper.php +++ b/src/helpers/DiagnosticsHelper.php @@ -13,9 +13,11 @@ use craft\db\Table; use craft\elements\GlobalSet; use craft\helpers\ArrayHelper; +use craft\helpers\Cp; use craft\helpers\DateTimeHelper; use craft\helpers\Db; use craft\helpers\Json; +use craft\helpers\Template; use craft\helpers\UrlHelper; use DateTime; use putyourlightson\blitz\Blitz; @@ -31,6 +33,7 @@ use putyourlightson\blitz\records\IncludeRecord; use putyourlightson\blitz\services\CacheRequestService; use putyourlightson\blitzhints\BlitzHints; +use Twig\Markup; use yii\db\ActiveRecordInterface; /** @@ -304,6 +307,22 @@ public static function getElementsFromIds(int $siteId, string $elementType, arra ->all(); } + public static function getElementChip(Element $element, ?string $uri = null): Markup + { + $value = Cp::elementHtml($element); + + if ($uri !== null) { + $url = UrlHelper::cpUrl($uri, [ + 'siteId' => $element->siteId, + 'elementId' => $element->id, + 'elementType' => $element::class, + ]); + $value = str_replace($element->getCpEditUrl(), $url, $value); + } + + return Template::raw($value); + } + public static function getPageTags(int $cacheId): array { $tags = CacheTagRecord::find() diff --git a/src/templates/_utilities/diagnostics/_components/elements.twig b/src/templates/_utilities/diagnostics/_components/elements.twig index b22aebbb..e720f67b 100644 --- a/src/templates/_utilities/diagnostics/_components/elements.twig +++ b/src/templates/_utilities/diagnostics/_components/elements.twig @@ -69,13 +69,7 @@ {% if element %} - - {{ element.title }} - + {{ craft.blitz.diagnostics.getElementChip(element, 'blitz/diagnostics/elements/pages-includes') }} {% if cacheId is defined %} diff --git a/src/templates/_utilities/diagnostics/elements/pages-includes.twig b/src/templates/_utilities/diagnostics/elements/pages-includes.twig index 245b09bb..6a1a5bf2 100644 --- a/src/templates/_utilities/diagnostics/elements/pages-includes.twig +++ b/src/templates/_utilities/diagnostics/elements/pages-includes.twig @@ -12,6 +12,12 @@ }, ] %} +{% block pageTitle %} +

+ {{ craft.blitz.diagnostics.getElementChip(element) }} +

+{% endblock %} + {% block content %} {{ sprig('blitz/_utilities/diagnostics/_components/pages', { siteId: siteId, diff --git a/tests/pest/Feature/GenerateCacheTest.php b/tests/pest/Feature/GenerateCacheTest.php index 2d7c39ce..9165736d 100644 --- a/tests/pest/Feature/GenerateCacheTest.php +++ b/tests/pest/Feature/GenerateCacheTest.php @@ -155,7 +155,6 @@ [ 'type' => 'test', 'fields' => [ - 'test' => '1', 'relatedTo' => [$childEntry->id], ], ],