Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- fix - event when the boolean `must_store_when_generating_url` option is set to `true`, the media is not stored when generating a URL using the twig `joli_media_url` filter

## [0.2.0] - 2024-12-01

- feature - added pagination to admin bridges media lists
Expand Down
1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@
->set('joli_media.twig_extension', JoliMediaExtension::class)
->args([
service('joli_media.resolver'),
service('joli_media.converter'),
])
->tag('twig.extension')

Expand Down
2 changes: 1 addition & 1 deletion src/Twig/Components/Picture.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function mount(
} catch (MediaNotFoundException) {
// the media cannot be found based on the path and library, so we create a fake media object
// to allow the component to render - there will obviously be a 404 error when trying to access the media
$media = new Media($path, $this->libraries->getDefault()->getOriginalStorage());
$media = new Media($path, $this->libraries->get($library)->getOriginalStorage());
}
}

Expand Down
14 changes: 13 additions & 1 deletion src/Twig/JoliMediaExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JoliCode\MediaBundle\Twig;

use JoliCode\MediaBundle\Conversion\Converter;
use JoliCode\MediaBundle\Model\Media;
use JoliCode\MediaBundle\Model\MediaVariation;
use JoliCode\MediaBundle\Resolver\Resolver;
Expand All @@ -13,6 +14,7 @@ class JoliMediaExtension extends AbstractExtension
{
public function __construct(
private readonly Resolver $resolver,
private readonly Converter $converter,
) {
}

Expand Down Expand Up @@ -40,7 +42,17 @@ private function getUrl(
?string $libraryName = null,
int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
): ?string {
return $this->getMediaVariation($path, $variationName, $libraryName)?->getUrl($referenceType);
$media = $this->getMediaVariation($path, $variationName, $libraryName);

if ($media instanceof MediaVariation) {
try {
$this->converter->convertIfMustStoreWhenGeneratingUrl($media);
} catch (\Exception) {
// ignore errors
}
}

return $media?->getUrl($referenceType);
}

private function getMediaVariation(
Expand Down