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

Fixed custom path generators for Media with morphed map relations #3191

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Update PathGeneratorFactory.php
freekmurze authored Mar 6, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 6b27d43f837fac6b566ff59cee7c1110185269f2
4 changes: 2 additions & 2 deletions src/Support/PathGenerator/PathGeneratorFactory.php
Original file line number Diff line number Diff line change
@@ -22,15 +22,15 @@ protected static function getPathGeneratorClass(Media $media)
$defaultPathGeneratorClass = config('media-library.path_generator');

foreach (config('media-library.custom_path_generators', []) as $modelClass => $customPathGeneratorClass) {
if (static::assertMediaModelTypeEqualsTo($media, $modelClass)) {
if (static::mediaBelongToModelClass($media, $modelClass)) {
return $customPathGeneratorClass;
}
}

return $defaultPathGeneratorClass;
}

protected static function assertMediaModelTypeEqualsTo(Media $media, string $modelClass): bool
protected static function mediaBelongToModelClass(Media $media, string $modelClass): bool
{
// model doesn't have morphMap, so morph type and class are equal
if (is_a($media->model_type, $modelClass, true)) {