Skip to content

Commit 28fe4d9

Browse files
committed
fix: resolve Heroicon enum icon names and accept int field IDs
Use ScalableIcon::getIconForSize() to get properly prefixed blade-icons names (e.g. heroicon-o-rectangle-stack) instead of raw enum values. Widen findField() parameter type to accept both string and int IDs.
1 parent 5a462dd commit 28fe4d9

2 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/Data/EntityConfigurationData.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Exception;
1212
use Filament\Facades\Filament;
1313
use Filament\Resources\Resource;
14+
use Filament\Support\Contracts\ScalableIcon;
15+
use Filament\Support\Enums\IconSize;
1416
use Illuminate\Database\Eloquent\Builder;
1517
use Illuminate\Database\Eloquent\Model;
1618
use Illuminate\Support\Collection;
@@ -110,18 +112,11 @@ public function getIcon(): string
110112
return once(function (): string {
111113
$icon = $this->icon;
112114

113-
// Handle Filament Heroicon enums
114-
if ($icon instanceof BackedEnum) {
115-
return $icon->value;
116-
}
117-
118-
// For any objects with a name property
119-
if (is_object($icon) && property_exists($icon, 'name')) {
120-
return $icon->name;
115+
if ($icon instanceof ScalableIcon) {
116+
return $icon->getIconForSize(IconSize::Medium);
121117
}
122118

123-
// For any objects with a value property
124-
if (is_object($icon) && property_exists($icon, 'value')) {
119+
if ($icon instanceof BackedEnum) {
125120
return $icon->value;
126121
}
127122

@@ -167,6 +162,10 @@ private function resolveIconFromFilamentResource(): ?string
167162

168163
$icon = $resourceClass::getNavigationIcon();
169164

165+
if ($icon instanceof ScalableIcon) {
166+
return $icon->getIconForSize(IconSize::Medium);
167+
}
168+
170169
if ($icon instanceof BackedEnum) {
171170
return $icon->value;
172171
}

src/Livewire/ManageFieldsTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function getFieldsQuery(): Builder
6262
->orderBy('sort_order');
6363
}
6464

65-
private function findField(string $fieldId): ?CustomField
65+
private function findField(string|int $fieldId): ?CustomField
6666
{
6767
return CustomFields::newCustomFieldModel()
6868
->newQuery()

0 commit comments

Comments
 (0)