|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of Monsieur Biz' Blog plugin for Sylius. |
| 5 | + * |
| 6 | + * (c) Monsieur Biz <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE.txt |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespace MonsieurBiz\SyliusBlogPlugin\Controller; |
| 15 | + |
| 16 | +use MonsieurBiz\SyliusRichEditorPlugin\Switcher\SwitchAdminLocaleInterface; |
| 17 | +use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
| 18 | +use Sylius\Component\Resource\ResourceActions; |
| 19 | +use Symfony\Component\HttpFoundation\Request; |
| 20 | +use Symfony\Component\HttpFoundation\Response; |
| 21 | + |
| 22 | +class ArticleController extends ResourceController |
| 23 | +{ |
| 24 | + public function previewAction(Request $request, SwitchAdminLocaleInterface $switchAdminLocale): Response |
| 25 | + { |
| 26 | + // Switch the locale of the preview to the default locale of the channel to not take the locale of the admin |
| 27 | + if ($locale = $request->getDefaultLocale()) { |
| 28 | + $switchAdminLocale->switchLocale($locale); |
| 29 | + } |
| 30 | + $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
| 31 | + |
| 32 | + $this->isGrantedOr403($configuration, ResourceActions::SHOW); |
| 33 | + $resource = $this->findOr404($configuration); |
| 34 | + |
| 35 | + /** @var string $template */ |
| 36 | + $template = $configuration->getRequest()->get('template'); |
| 37 | + |
| 38 | + return $this->render($template, [ |
| 39 | + 'configuration' => $configuration, |
| 40 | + 'metadata' => $this->metadata, |
| 41 | + 'resource' => $resource, |
| 42 | + $this->metadata->getName() => $resource, |
| 43 | + ]); |
| 44 | + } |
| 45 | +} |
0 commit comments