From 63d592145605f13eabc681533bbcd370f6bf90e5 Mon Sep 17 00:00:00 2001 From: Patryk Drapik Date: Sun, 26 Apr 2020 14:41:38 +0200 Subject: [PATCH] Added option to override media rendering templates --- src/Controller/MediaController.php | 2 +- src/MediaProvider/GenericProvider.php | 4 ++-- src/MediaProvider/ProviderInterface.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Controller/MediaController.php b/src/Controller/MediaController.php index 78a91176b..3dd1e28bb 100755 --- a/src/Controller/MediaController.php +++ b/src/Controller/MediaController.php @@ -42,7 +42,7 @@ public function renderMediaAction(Request $request): Response $mediaProviderResolver = $this->get('bitbag_sylius_cms_plugin.resolver.media_provider'); - return new Response($mediaProviderResolver->resolveProvider($media)->render($media)); + return new Response($mediaProviderResolver->resolveProvider($media)->render($media, $request->get('template'))); } public function downloadMediaAction(Request $request): Response diff --git a/src/MediaProvider/GenericProvider.php b/src/MediaProvider/GenericProvider.php index 9dc970560..988cc61dd 100755 --- a/src/MediaProvider/GenericProvider.php +++ b/src/MediaProvider/GenericProvider.php @@ -47,9 +47,9 @@ public function getTemplate(): string return $this->template; } - public function render(MediaInterface $media, array $options = []): string + public function render(MediaInterface $media, ?string $template = null, array $options = []): string { - return $this->twigEngine->render($this->template, array_merge(['media' => $media], $options)); + return $this->twigEngine->render($template ?? $this->template, array_merge(['media' => $media], $options)); } public function upload(MediaInterface $media): void diff --git a/src/MediaProvider/ProviderInterface.php b/src/MediaProvider/ProviderInterface.php index 7cfa73170..c511305a9 100644 --- a/src/MediaProvider/ProviderInterface.php +++ b/src/MediaProvider/ProviderInterface.php @@ -18,7 +18,7 @@ interface ProviderInterface { public function getTemplate(): string; - public function render(MediaInterface $media, array $options = []): string; + public function render(MediaInterface $media, ?string $template = null, array $options = []): string; public function upload(MediaInterface $media): void; }