1 | <?php |
||||
2 | |||||
3 | /* |
||||
4 | * This file was created by developers working at BitBag |
||||
5 | * Do you need more information about us and what we do? Visit our https://bitbag.io website! |
||||
6 | * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career |
||||
7 | */ |
||||
8 | |||||
9 | declare(strict_types=1); |
||||
10 | |||||
11 | namespace BitBag\SyliusCmsPlugin\Controller; |
||||
12 | |||||
13 | use BitBag\SyliusCmsPlugin\Entity\BlockInterface; |
||||
14 | use BitBag\SyliusCmsPlugin\Resolver\BlockResourceResolverInterface; |
||||
15 | use FOS\RestBundle\View\View; |
||||
16 | use Sylius\Bundle\ResourceBundle\Controller\ResourceController; |
||||
17 | use Sylius\Component\Resource\ResourceActions; |
||||
18 | use Symfony\Component\HttpFoundation\Request; |
||||
19 | use Symfony\Component\HttpFoundation\Response; |
||||
20 | use Webmozart\Assert\Assert; |
||||
21 | |||||
22 | final class BlockController extends ResourceController |
||||
23 | { |
||||
24 | public const BLOCK_TEMPLATE = '@BitBagSyliusCmsPlugin/Shop/Block/show.html.twig'; |
||||
25 | |||||
26 | public function renderBlockAction(Request $request): Response |
||||
27 | { |
||||
28 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||||
29 | |||||
30 | $this->isGrantedOr403($configuration, ResourceActions::SHOW); |
||||
31 | |||||
32 | $code = $request->get('code'); |
||||
33 | /** @var BlockResourceResolverInterface $blockResourceResolver */ |
||||
34 | $blockResourceResolver = $this->get('bitbag_sylius_cms_plugin.resolver.block_resource'); |
||||
35 | $block = $blockResourceResolver->findOrLog($code); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
36 | |||||
37 | if (null === $block) { |
||||
38 | return new Response(); |
||||
39 | } |
||||
40 | |||||
41 | $this->eventDispatcher->dispatch(ResourceActions::SHOW, $configuration, $block); |
||||
42 | |||||
43 | if (!$configuration->isHtmlRequest()) { |
||||
44 | Assert::true(null !== $this->viewHandler); |
||||
45 | |||||
46 | return $this->viewHandler->handle($configuration, View::create($block)); |
||||
0 ignored issues
–
show
The method
handle() does not exist on null .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||||
47 | } |
||||
48 | |||||
49 | $template = $request->get('template') ?? self::BLOCK_TEMPLATE; |
||||
50 | |||||
51 | return $this->render($template, [ |
||||
52 | 'configuration' => $configuration, |
||||
53 | 'metadata' => $this->metadata, |
||||
54 | 'resource' => $block, |
||||
55 | $this->metadata->getName() => $block, |
||||
56 | ]); |
||||
57 | } |
||||
58 | |||||
59 | public function previewAction(Request $request): Response |
||||
60 | { |
||||
61 | $configuration = $this->requestConfigurationFactory->create($this->metadata, $request); |
||||
62 | |||||
63 | $this->isGrantedOr403($configuration, ResourceActions::CREATE); |
||||
64 | /** @var BlockInterface $block */ |
||||
65 | $block = $this->newResourceFactory->create($configuration, $this->factory); |
||||
66 | $form = $this->resourceFormFactory->create($configuration, $block); |
||||
67 | |||||
68 | $form->handleRequest($request); |
||||
69 | |||||
70 | /** @var BlockInterface $block */ |
||||
71 | $block = $form->getData(); |
||||
72 | $defaultLocale = $this->getParameter('locale'); |
||||
73 | |||||
74 | $block->setFallbackLocale($request->get('_locale', $defaultLocale)); |
||||
75 | $block->setCurrentLocale($request->get('_locale', $defaultLocale)); |
||||
76 | |||||
77 | if (!$configuration->isHtmlRequest()) { |
||||
78 | Assert::true(null !== $this->viewHandler); |
||||
79 | |||||
80 | return $this->viewHandler->handle($configuration, View::create($block)); |
||||
81 | } |
||||
82 | |||||
83 | return $this->render($configuration->getTemplate(ResourceActions::CREATE . '.html'), [ |
||||
84 | 'resource' => $block, |
||||
85 | $this->metadata->getName() => $block, |
||||
86 | 'blockTemplate' => self::BLOCK_TEMPLATE, |
||||
87 | ]); |
||||
88 | } |
||||
89 | } |
||||
90 |