Add icon to file

This commit is contained in:
Philipp Lang 2023-03-10 12:47:14 +01:00
parent 0c10472e2e
commit 61ed6e0a3d
3 changed files with 13 additions and 0 deletions

2
.gitignore vendored
View File

@ -1 +1,3 @@
/vendor/ /vendor/
/.php-cs-fixer.cache
/.phpunit.result.cache

View File

@ -3,6 +3,7 @@
namespace Zoomyboy\MedialibraryHelper; namespace Zoomyboy\MedialibraryHelper;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Spatie\LaravelData\Attributes\MapInputName; use Spatie\LaravelData\Attributes\MapInputName;
use Spatie\LaravelData\Attributes\MapOutputName; use Spatie\LaravelData\Attributes\MapOutputName;
use Spatie\LaravelData\Data; use Spatie\LaravelData\Data;
@ -48,6 +49,15 @@ class MediaData extends Data
]); ]);
} }
public function with(): array
{
$mime = Str::slug($this->mimeType);
return [
'icon' => Storage::disk('public')->url("filetypes/{$mime}.svg"),
];
}
public static function defaultFromCollection(HasMedia $parent, MediaCollection $collection): ?self public static function defaultFromCollection(HasMedia $parent, MediaCollection $collection): ?self
{ {
$default = $collection->runCallback('withFallback', $parent); $default = $collection->runCallback('withFallback', $parent);

View File

@ -16,6 +16,7 @@ test('it gets all medias', function () {
$response->assertJsonPath('0.id', $firstMedia->id); $response->assertJsonPath('0.id', $firstMedia->id);
$response->assertJsonPath('1.id', $secondMedia->id); $response->assertJsonPath('1.id', $secondMedia->id);
$response->assertJsonPath('1.properties.test', 'old'); $response->assertJsonPath('1.properties.test', 'old');
$response->assertJsonPath('1.icon', url('storage/filetypes/applicationpdf.svg'));
}); });
test('it gets media for single', function () { test('it gets media for single', function () {