Skip to content

Commit

Permalink
Added option to override media rendering templates
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick477 committed Apr 26, 2020
1 parent 63f3472 commit 63d5921
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Controller/MediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/MediaProvider/GenericProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/MediaProvider/ProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 63d5921

Please sign in to comment.