From 235936809e78769ec945337c2fb2881a61fb9195 Mon Sep 17 00:00:00 2001 From: Manuk Date: Sat, 7 Nov 2026 21:54:31 +0400 Subject: [PATCH] fix: show the entity icon for a linked record without an image on view pages --- .../views/infolists/record-entry.blade.php | 8 +- .../Components/Infolists/RecordEntry.php | 1 + .../Filament/Components/RecordEntryTest.php | 80 +++++++++++++++++++ 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 tests/Feature/Filament/Components/RecordEntryTest.php diff --git a/resources/views/infolists/record-entry.blade.php b/resources/views/infolists/record-entry.blade.php index 130691787..e7952e4ec 100644 --- a/resources/views/infolists/record-entry.blade.php +++ b/resources/views/infolists/record-entry.blade.php @@ -11,16 +11,12 @@ - @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/Infolists/RecordEntry.php b/src/Filament/Integration/Components/Infolists/RecordEntry.php index 80bc9db4b..0a18cf121 100644 --- a/src/Filament/Integration/Components/Infolists/RecordEntry.php +++ b/src/Filament/Integration/Components/Infolists/RecordEntry.php @@ -74,6 +74,7 @@ private function formatRecord( 'name' => $name, 'avatarUrl' => $avatarUrl, 'avatarShape' => $shapeClass, + 'icon' => blank($avatarUrl) && $avatarConfig?->hasAttribute() ? $entity->getIcon() : null, 'url' => $url, ]; } diff --git a/tests/Feature/Filament/Components/RecordEntryTest.php b/tests/Feature/Filament/Components/RecordEntryTest.php new file mode 100644 index 000000000..d435b77c2 --- /dev/null +++ b/tests/Feature/Filament/Components/RecordEntryTest.php @@ -0,0 +1,80 @@ +record($this->post) + ->components([CustomFields::infolist()->forModel($this->post)->build()]); + } + + public function render(): string + { + return '
{{ $this->infolist }}
'; + } +} + +describe('RecordEntry', 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, + ]); + }); + + 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]); + + $withImage = Post::factory()->create(); + $withImage->saveCustomFieldValue($this->field, $pictured->getKey()); + + $withoutImage = Post::factory()->create(); + $withoutImage->saveCustomFieldValue($this->field, $unpictured->getKey()); + + livewire(ViewPostCustomFields::class, ['post' => $withImage]) + ->assertSeeHtml('src="https://example.test/cover.png"') + ->assertDontSeeHtml('data-record-icon'); + + livewire(ViewPostCustomFields::class, ['post' => $withoutImage]) + ->assertSee($unpictured->title) + ->assertSeeHtml('data-record-icon'); + }); + + 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 = Post::factory()->create(); + $post->saveCustomFieldValue($this->field, $linked->getKey()); + + livewire(ViewPostCustomFields::class, ['post' => $post]) + ->assertSee($linked->title) + ->assertDontSeeHtml('data-record-icon'); + }); +});