From 4a87b83b5a83d9833696f3b8be5c57c7ec19ff60 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Wed, 30 Oct 2024 15:25:43 +0100 Subject: [PATCH] Add pathinfo information to default Properties --- src/CollectionExtension.php | 5 +++-- src/MediaController.php | 2 +- tests/Models/Post.php | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/CollectionExtension.php b/src/CollectionExtension.php index a268d6f..a3aa67e 100644 --- a/src/CollectionExtension.php +++ b/src/CollectionExtension.php @@ -8,7 +8,8 @@ class CollectionExtension { public function boot(): void { - MediaCollection::mixin(new class() { + MediaCollection::mixin(new class() + { public function forceFileName() { return fn ($callback) => $this->registerCustomCallback('forceFileName', $callback); @@ -86,7 +87,7 @@ class CollectionExtension 'after' => fn ($event) => true, 'destroyed' => fn ($event) => true, 'storing' => fn ($adder, $name) => $adder, - 'withDefaultProperties' => fn ($path) => [], + 'withDefaultProperties' => fn ($path, $pathinfo) => [], 'withPropertyValidation' => fn ($path) => [], 'withFallback' => fn ($parent) => null, ]); diff --git a/src/MediaController.php b/src/MediaController.php index 911a56b..6c44b61 100644 --- a/src/MediaController.php +++ b/src/MediaController.php @@ -54,7 +54,7 @@ class MediaController $adder = $this->fileAdderFromData($model, $c['content'], $collection) ->usingName($basename) ->usingFileName($path) - ->withCustomProperties($collection->runCallback('withDefaultProperties', $path)); + ->withCustomProperties($collection->runCallback('withDefaultProperties', $path, $pathinfo)); return tap( $collection->runCallback('storing', $adder, $path)->toMediaCollection($collection->name), diff --git a/tests/Models/Post.php b/tests/Models/Post.php index 5b18122..225366d 100644 --- a/tests/Models/Post.php +++ b/tests/Models/Post.php @@ -56,7 +56,7 @@ class Post extends Model implements HasMedia Event::dispatch(new MediaStored($media)); }); - $this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path) => [ + $this->addMediaCollection('multipleProperties')->singleFile()->withDefaultProperties(fn ($path, $pathinfo) => [ 'test' => Str::camel($path), ])->withPropertyValidation(fn ($path) => [ 'test' => 'string|max:10',