Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileAdder - Resolve media model from subject and reinforce HasMedia contract #3547

Merged
merged 1 commit into from
Feb 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
resolve media model from subject if available and enforce HasMedia co…
…ntract
illambo committed Feb 17, 2024
commit 44e8e10f27a8b819b855c0196ca6fd88caed29b9
2 changes: 2 additions & 0 deletions src/HasMedia.php
Original file line number Diff line number Diff line change
@@ -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
@@ -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();

@@ -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();