Skip to content

Commit 720ce51

Browse files
authored
Merge pull request #73 from jolicode/feat/generate-variation-twig-extension
Generate a variation when the twig extension outputs the variation URL
2 parents 4f4e0d9 + 5f6c136 commit 720ce51

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- 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
6+
37
## [0.2.0] - 2024-12-01
48

59
- feature - added pagination to admin bridges media lists

config/services.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@
458458
->set('joli_media.twig_extension', JoliMediaExtension::class)
459459
->args([
460460
service('joli_media.resolver'),
461+
service('joli_media.converter'),
461462
])
462463
->tag('twig.extension')
463464

src/Twig/Components/Picture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function mount(
6060
} catch (MediaNotFoundException) {
6161
// the media cannot be found based on the path and library, so we create a fake media object
6262
// to allow the component to render - there will obviously be a 404 error when trying to access the media
63-
$media = new Media($path, $this->libraries->getDefault()->getOriginalStorage());
63+
$media = new Media($path, $this->libraries->get($library)->getOriginalStorage());
6464
}
6565
}
6666

src/Twig/JoliMediaExtension.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace JoliCode\MediaBundle\Twig;
44

5+
use JoliCode\MediaBundle\Conversion\Converter;
56
use JoliCode\MediaBundle\Model\Media;
67
use JoliCode\MediaBundle\Model\MediaVariation;
78
use JoliCode\MediaBundle\Resolver\Resolver;
@@ -13,6 +14,7 @@ class JoliMediaExtension extends AbstractExtension
1314
{
1415
public function __construct(
1516
private readonly Resolver $resolver,
17+
private readonly Converter $converter,
1618
) {
1719
}
1820

@@ -40,7 +42,17 @@ private function getUrl(
4042
?string $libraryName = null,
4143
int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH,
4244
): ?string {
43-
return $this->getMediaVariation($path, $variationName, $libraryName)?->getUrl($referenceType);
45+
$media = $this->getMediaVariation($path, $variationName, $libraryName);
46+
47+
if ($media instanceof MediaVariation) {
48+
try {
49+
$this->converter->convertIfMustStoreWhenGeneratingUrl($media);
50+
} catch (\Exception) {
51+
// ignore errors
52+
}
53+
}
54+
55+
return $media?->getUrl($referenceType);
4456
}
4557

4658
private function getMediaVariation(

0 commit comments

Comments
 (0)