Skip to content

Commit

Permalink
Add element chips
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Jul 24, 2024
1 parent 0858211 commit ff3774d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 19 additions & 0 deletions src/helpers/DiagnosticsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,7 @@
{% if element %}
<tr>
<td>
<a href="{{ url('blitz/diagnostics/elements/pages-includes', {
siteId: siteId,
elementId: element.id,
elementType: elementType,
}) }}">
{{ element.title }}
</a>
{{ craft.blitz.diagnostics.getElementChip(element, 'blitz/diagnostics/elements/pages-includes') }}
</td>
{% if cacheId is defined %}
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
},
] %}

{% block pageTitle %}
<h1>
{{ craft.blitz.diagnostics.getElementChip(element) }}
</h1>
{% endblock %}

{% block content %}
{{ sprig('blitz/_utilities/diagnostics/_components/pages', {
siteId: siteId,
Expand Down
1 change: 0 additions & 1 deletion tests/pest/Feature/GenerateCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
[
'type' => 'test',
'fields' => [
'test' => '1',
'relatedTo' => [$childEntry->id],
],
],
Expand Down

0 comments on commit ff3774d

Please sign in to comment.