Skip to content

Commit

Permalink
Revert exception.
Browse files Browse the repository at this point in the history
  • Loading branch information
haringsrob committed Apr 1, 2022
1 parent 479fa22 commit 308d4e3
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/Models/Behaviors/HasMedias.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,36 +52,22 @@ public function medias()
->withTimestamps()->orderBy(config('twill.mediables_table', 'twill_mediables') . '.id', 'asc');
}

private function findMedia($role, $crop = "default")
private function findMedia($role, $crop = 'default')
{
$foundMedia = false;
$media = $this->medias->first(function ($media) use ($role, $crop, &$foundMedia) {
$media = $this->medias->first(function ($media) use ($role, $crop) {
if (config('twill.media_library.translated_form_fields', false)) {
$localeScope = $media->pivot->locale === app()->getLocale();
}

if (!$foundMedia) {
$foundMedia = $media->pivot->role === $role && ($localeScope ?? true);
}

return $foundMedia && $media->pivot->crop === $crop;
return $media->pivot->role === $role && $media->pivot->crop === $crop && ($localeScope ?? true);
});

if (!$media && config('twill.media_library.translated_form_fields', false)) {
$media = $this->medias->first(function ($media) use ($role, $crop, &$foundMedia) {
if (!$foundMedia) {
$foundMedia = $media->pivot->role === $role;
}

return $foundMedia && $media->pivot->crop === $crop;
if (! $media && config('twill.media_library.translated_form_fields', false)) {
$media = $this->medias->first(function ($media) use ($role, $crop) {
return $media->pivot->role === $role && $media->pivot->crop === $crop;
});
}

if ($foundMedia && !$media && config('app.debug')) {
// In this case we found the media but not the crop because our result is still empty.
throw new MediaCropNotFoundException($crop);
}

return $media;
}

Expand Down

0 comments on commit 308d4e3

Please sign in to comment.