Skip to content

Commit 5e793e6

Browse files
committed
feat: add eager loading support to IconManagerField
- Implement EagerLoadingFieldInterface for compatibility with Craft's .with() syntax - Resolves "icon not found" errors when using eager loading in templates - Maintains full backwards compatibility with existing field behavior - Preserves all existing caching functionality
1 parent 9615697 commit 5e793e6

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/fields/IconManagerField.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@
1818
use craft\base\Field;
1919
use craft\base\PreviewableFieldInterface;
2020
use craft\base\SortableFieldInterface;
21-
use craft\db\Query;
21+
use craft\base\EagerLoadingFieldInterface;
2222
use craft\helpers\Html;
2323
use craft\helpers\Json;
2424

2525
/**
2626
* Icon Manager Field
2727
*/
28-
class IconManagerField extends Field implements PreviewableFieldInterface, SortableFieldInterface
28+
class IconManagerField extends Field implements PreviewableFieldInterface, SortableFieldInterface, EagerLoadingFieldInterface
2929
{
3030
/**
3131
* @var array Allowed icon sets for this field
@@ -412,4 +412,23 @@ private function _createIconFromArray(array $data, ?ElementInterface $element =
412412
return $icon;
413413
}
414414

415+
/**
416+
* @inheritdoc
417+
*/
418+
public function getEagerLoadingMap(array $sourceElements): array|null|false
419+
{
420+
// For non-element fields, we just return null to indicate no eager loading needed
421+
// Craft will handle the field values normally through normalizeValue()
422+
return null;
423+
}
424+
425+
/**
426+
* @inheritdoc
427+
*/
428+
public function getEagerLoadingGqlConditions(): ?array
429+
{
430+
// Allow all conditions for GraphQL
431+
return null;
432+
}
433+
415434
}

0 commit comments

Comments
 (0)