Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Feb 26, 2024
1 parent 171b5ec commit 98d9779
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
13 changes: 6 additions & 7 deletions src/services/HintsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,17 @@ public function clear(int $id): void
*/
public function checkElementQuery(ElementQuery $elementQuery): void
{
if ($elementQuery->eagerLoadHandle === null) {
if ($elementQuery->wasEagerLoaded() || $elementQuery->eagerLoadHandle === null) {
return;
}

$fieldHandle = last(explode(':', $elementQuery->eagerLoadHandle));

if ($fieldHandle === null) {
return;
/** @see ElementQuery::wasEagerLoaded() */
$planHandle = $elementQuery->eagerLoadHandle;
if (str_contains($planHandle, ':')) {
$planHandle = explode(':', $planHandle, 2)[1];
}

$fieldId = Craft::$app->getFields()->getFieldByHandle($fieldHandle)->id ?? null;

$fieldId = Craft::$app->getFields()->getFieldByHandle($planHandle)->id ?? null;
if ($fieldId === null) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pest/Feature/HintsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
});

test('Hint is not recorded for a related element query that is lazy-loaded in a template that exist in the vendor folder path', function() {
saveHint(Craft::getAlias('@vendor/templates/test'));
saveHint(template: Craft::getAlias('@vendor/templates/test'));

expect(HintRecord::find()->count())
->toEqual(0);
Expand Down
5 changes: 3 additions & 2 deletions tests/pest/Pest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use craft\elements\db\ElementQuery;
use craft\elements\Entry;
use markhuot\craftpest\test\TestCase;
use putyourlightson\blitzhints\BlitzHints;
Expand Down Expand Up @@ -48,10 +49,10 @@
|
*/

function saveHint(?string $template = null): void
function saveHint(?ElementQuery $elementQuery = null, ?string $template = null): void
{
$elementQuery = $elementQuery ?? Entry::find()->section('single')->one()->relatedTo;
$template = $template ?? 'templates/test';
$elementQuery = Entry::find()->section('single')->one()->relatedTo;

$fieldId = Craft::$app->getFields()->getFieldByHandle('relatedTo')->id;
$hint = new HintModel([
Expand Down

0 comments on commit 98d9779

Please sign in to comment.