Skip to content

Commit

Permalink
resolve media model from subject if available and enforce HasMedia co…
Browse files Browse the repository at this point in the history
…ntract (#3547)
  • Loading branch information
illambo authored Feb 20, 2024
1 parent 703ca88 commit d36b8f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/HasMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,6 @@ public function registerMediaConversions(?Media $media = null): void;
public function registerMediaCollections(): void;

public function registerAllMediaConversions(): void;

public function getMediaModel(): string;
}
4 changes: 2 additions & 2 deletions src/MediaCollections/FileAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public function toMediaCollectionFromRemote(string $collectionName = 'default',
throw FileIsTooBig::create($this->pathToFile, $storage->size($this->pathToFile));
}

$mediaClass = config('media-library.media_model');
$mediaClass = $this->subject?->getMediaModel() ?? config('media-library.media_model');
/** @var Media $media */
$media = new $mediaClass();

Expand Down Expand Up @@ -300,7 +300,7 @@ public function toMediaCollection(string $collectionName = 'default', string $di
throw FileIsTooBig::create($this->pathToFile);
}

$mediaClass = config('media-library.media_model');
$mediaClass = $this->subject?->getMediaModel() ?? config('media-library.media_model');
/** @var Media $media */
$media = new $mediaClass();

Expand Down

0 comments on commit d36b8f2

Please sign in to comment.