diff --git a/resources/views/forms/record-select-input.blade.php b/resources/views/forms/record-select-input.blade.php
index af3b78633..4c308459f 100644
--- a/resources/views/forms/record-select-input.blade.php
+++ b/resources/views/forms/record-select-input.blade.php
@@ -17,6 +17,7 @@
$selectedIds = is_array($state) ? array_filter($state) : [];
$initialRecords = $getRecordsByIds($selectedIds);
$initialOptions = $getInitialOptions();
+ $fallbackIcon = $getFallbackIcon();
@endphp
+ @if ($fallbackIcon)
+
+
+
+
+
+ @endif
@@ -532,6 +544,17 @@ class="h-5 w-5 object-cover"
alt=""
/>
+ @if ($fallbackIcon)
+
+
+
+
+
+ @endif
+ @if ($fallbackIcon)
+
+
+
+
+
+ @endif
{{-- Label --}}
+@elseif ($record['icon'])
+
+
+
+@endif
diff --git a/resources/views/tables/columns/record-column.blade.php b/resources/views/tables/columns/record-column.blade.php
index a8f94b769..f1a713d8d 100644
--- a/resources/views/tables/columns/record-column.blade.php
+++ b/resources/views/tables/columns/record-column.blade.php
@@ -30,7 +30,7 @@
x-on:keydown.enter.prevent="togglePanel()"
x-on:keydown.space.prevent="togglePanel()"
@endif
- class="relative {{ $hiddenCount > 0 ? 'cursor-pointer' : '' }}"
+ class="fi-ta-text relative {{ $hiddenCount > 0 ? 'cursor-pointer' : '' }}"
>
@if (empty($records))
{{-- Empty: no value --}}
@@ -44,24 +44,12 @@ class="relative {{ $hiddenCount > 0 ? 'cursor-pointer' : '' }}"
x-on:click.stop
class="inline-flex items-center gap-2 py-0.5 px-1 -mx-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors shrink-0"
>
- @if ($record['avatarUrl'])
-
- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@else
- @if ($record['avatarUrl'])
-
- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@endif
@@ -97,24 +85,12 @@ class="px-2 py-1 hover:bg-gray-50 dark:hover:bg-gray-800 transition-colors"
x-on:click.stop
class="inline-flex items-center gap-2 py-0.5 px-1 -mx-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors w-full"
>
- @if ($record['avatarUrl'])
-
- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@else
- @if ($record['avatarUrl'])
-

- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@endif
@@ -134,24 +110,12 @@ class="h-5 w-5 {{ $record['avatarShape'] }} object-cover shrink-0"
x-on:click.stop
class="inline-flex items-center gap-2 py-0.5 px-1 -mx-1 rounded hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors"
>
- @if ($record['avatarUrl'])
-
- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@else
- @if ($record['avatarUrl'])
-

- @endif
+ @include('custom-fields::tables.columns.partials.record-avatar', ['record' => $record])
{{ $record['name'] }}
@endif
diff --git a/src/Filament/Integration/Components/Forms/RecordSelectInput/RecordSelectInputComponent.php b/src/Filament/Integration/Components/Forms/RecordSelectInput/RecordSelectInputComponent.php
index f6011196d..ca667e7e3 100644
--- a/src/Filament/Integration/Components/Forms/RecordSelectInput/RecordSelectInputComponent.php
+++ b/src/Filament/Integration/Components/Forms/RecordSelectInput/RecordSelectInputComponent.php
@@ -176,6 +176,17 @@ public function getEntityConfiguration(): ?EntityConfigurationData
return Entities::getEntity($lookupType);
}
+ public function getFallbackIcon(): ?string
+ {
+ $entity = $this->getEntityConfiguration();
+
+ if (! $entity?->getAvatarConfiguration()?->hasAttribute()) {
+ return null;
+ }
+
+ return $entity->getIcon();
+ }
+
/**
* Prepare entity query with common attributes.
*
diff --git a/src/Filament/Integration/Components/Tables/Columns/RecordColumn.php b/src/Filament/Integration/Components/Tables/Columns/RecordColumn.php
index a7f6c8fa4..76be0cc37 100644
--- a/src/Filament/Integration/Components/Tables/Columns/RecordColumn.php
+++ b/src/Filament/Integration/Components/Tables/Columns/RecordColumn.php
@@ -109,6 +109,7 @@ private function formatRecord(Model $record): array
'name' => $name,
'avatarUrl' => $avatarUrl,
'avatarShape' => $shapeClass,
+ 'icon' => blank($avatarUrl) && $this->avatarConfig?->hasAttribute() ? $this->entity?->getIcon() : null,
'url' => $url,
];
}
diff --git a/tests/Feature/Filament/Components/RecordSelectSearchTest.php b/tests/Feature/Filament/Components/RecordSelectSearchTest.php
index fdf6f31f0..9cd054042 100644
--- a/tests/Feature/Filament/Components/RecordSelectSearchTest.php
+++ b/tests/Feature/Filament/Components/RecordSelectSearchTest.php
@@ -57,4 +57,26 @@
->assertSee('minSearchLength: 3', escape: false)
->assertSee('Type at least 3 characters to search', escape: false);
});
+
+ it('offers the entity icon in place of a missing image when the entity has one', function (bool $hasImageSetting): void {
+ registerLookupEntity(Post::class, primaryAttribute: 'title', avatarAttribute: $hasImageSetting ? 'cover_url' : null, icon: 'heroicon-o-newspaper');
+
+ $section = CustomFieldSection::factory()->forEntityType(Post::class)->create();
+
+ CustomField::factory()->create([
+ 'code' => 'related_post',
+ 'name' => 'Related Post',
+ 'type' => 'record',
+ 'entity_type' => Post::class,
+ 'lookup_type' => Post::class,
+ 'custom_field_section_id' => $section->getKey(),
+ ]);
+
+ $html = livewire(EditPost::class, ['record' => makeLookupRecord('Acme Industries')->getRouteKey()])->html();
+
+ expect(str_contains($html, 'data-record-icon'))->toBe($hasImageSetting);
+ })->with([
+ 'with an image setting' => [true],
+ 'without an image setting' => [false],
+ ]);
});
diff --git a/tests/Feature/Integration/Resources/Pages/ListRecordsTest.php b/tests/Feature/Integration/Resources/Pages/ListRecordsTest.php
index fb5018ea1..0ad36400f 100644
--- a/tests/Feature/Integration/Resources/Pages/ListRecordsTest.php
+++ b/tests/Feature/Integration/Resources/Pages/ListRecordsTest.php
@@ -505,3 +505,40 @@
->assertCanNotSeeTableRecords([$archived]);
});
});
+
+describe('Record column avatars', function (): void {
+ beforeEach(function (): void {
+ $this->field = CustomField::factory()->create([
+ 'custom_field_section_id' => CustomFieldSection::factory()->forEntityType(Post::class)->create(['active' => true])->getKey(),
+ 'name' => 'Related Post',
+ 'code' => 'related_post',
+ 'type' => 'record',
+ 'entity_type' => Post::class,
+ 'lookup_type' => Post::class,
+ 'settings' => new CustomFieldSettingsData(visible_in_list: true, list_toggleable_hidden: false),
+ ]);
+ });
+
+ it('shows the entity icon for a linked record without an image and the image for one with it', function (): void {
+ registerLookupEntity(Post::class, primaryAttribute: 'title', avatarAttribute: 'cover_url', icon: 'heroicon-o-newspaper');
+
+ $pictured = Post::factory()->create(['cover_url' => 'https://example.test/cover.png']);
+ $unpictured = Post::factory()->create(['cover_url' => null]);
+ Post::factory()->create()->saveCustomFieldValue($this->field, $pictured->getKey());
+ Post::factory()->create()->saveCustomFieldValue($this->field, $unpictured->getKey());
+
+ $html = livewire(ListPosts::class)->html();
+
+ expect(substr_count($html, 'src="https://example.test/cover.png"'))->toBe(1)
+ ->and(substr_count($html, 'data-record-icon'))->toBe(1);
+ });
+
+ it('shows no icon for a linked record whose entity has no image', function (): void {
+ registerLookupEntity(Post::class, primaryAttribute: 'title');
+
+ $linked = Post::factory()->create();
+ Post::factory()->create()->saveCustomFieldValue($this->field, $linked->getKey());
+
+ expect(livewire(ListPosts::class)->html())->not->toContain('data-record-icon');
+ });
+});
diff --git a/tests/Helpers.php b/tests/Helpers.php
index 5b8784448..248442b3e 100644
--- a/tests/Helpers.php
+++ b/tests/Helpers.php
@@ -16,7 +16,7 @@
*
* @param array $searchAttributes
*/
-function registerLookupEntity(string $modelClass, string $primaryAttribute, array $searchAttributes = []): void
+function registerLookupEntity(string $modelClass, string $primaryAttribute, array $searchAttributes = [], ?string $avatarAttribute = null, string $icon = 'heroicon-o-document'): void
{
config()->set('custom-fields.entity_configuration',
EntityConfigurator::configure()
@@ -25,9 +25,11 @@ function registerLookupEntity(string $modelClass, string $primaryAttribute, arra
->models([
EntityModel::configure(
modelClass: $modelClass,
+ icon: $icon,
primaryAttribute: $primaryAttribute,
searchAttributes: $searchAttributes,
features: [EntityFeature::CUSTOM_FIELDS, EntityFeature::LOOKUP_SOURCE],
+ avatarConfiguration: $avatarAttribute === null ? null : EntityModel::avatar(attribute: $avatarAttribute),
),
])
);
diff --git a/tests/database/migrations/create_posts_table.php b/tests/database/migrations/create_posts_table.php
index 8fea89051..1ebdae8f1 100644
--- a/tests/database/migrations/create_posts_table.php
+++ b/tests/database/migrations/create_posts_table.php
@@ -16,6 +16,7 @@ public function up(): void
$table->unsignedTinyInteger('rating')->default(0);
$table->json('tags')->nullable();
$table->string('title');
+ $table->string('cover_url')->nullable();
$table->json('json')->nullable();
$table->json('json_array_of_objects')->nullable();
$table->string('string_backed_enum')->nullable();