|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace BitBag\SyliusCmsPlugin\Twig\Extension; |
|
6
|
|
|
|
|
7
|
|
|
use BitBag\SyliusCmsPlugin\Repository\PageRepositoryInterface; |
|
8
|
|
|
use BitBag\SyliusCmsPlugin\Repository\SectionRepositoryInterface; |
|
9
|
|
|
use Sylius\Component\Channel\Context\ChannelContextInterface; |
|
10
|
|
|
use Sylius\Component\Locale\Context\LocaleContextInterface; |
|
11
|
|
|
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface; |
|
12
|
|
|
use Twig\Extension\AbstractExtension; |
|
13
|
|
|
|
|
14
|
|
|
final class RenderSectionPagesExtension extends AbstractExtension |
|
15
|
|
|
{ |
|
16
|
|
|
/** @var PageRepositoryInterface */ |
|
17
|
|
|
private $pageRepository; |
|
18
|
|
|
|
|
19
|
|
|
/** @var SectionRepositoryInterface */ |
|
20
|
|
|
private $sectionRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** @var ChannelContextInterface */ |
|
23
|
|
|
private $channelContext; |
|
24
|
|
|
|
|
25
|
|
|
/** @var LocaleContextInterface */ |
|
26
|
|
|
private $localeContext; |
|
27
|
|
|
|
|
28
|
|
|
/** @var EngineInterface */ |
|
29
|
|
|
private $templatingEngine; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct( |
|
32
|
|
|
PageRepositoryInterface $pageRepository, |
|
33
|
|
|
SectionRepositoryInterface $sectionRepository, |
|
34
|
|
|
ChannelContextInterface $channelContext, |
|
35
|
|
|
LocaleContextInterface $localeContext, |
|
36
|
|
|
EngineInterface $templatingEngine |
|
37
|
|
|
) { |
|
38
|
|
|
$this->pageRepository = $pageRepository; |
|
39
|
|
|
$this->sectionRepository = $sectionRepository; |
|
40
|
|
|
$this->channelContext = $channelContext; |
|
41
|
|
|
$this->localeContext = $localeContext; |
|
42
|
|
|
$this->templatingEngine = $templatingEngine; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function getFunctions(): array |
|
46
|
|
|
{ |
|
47
|
|
|
return [ |
|
48
|
|
|
new \Twig_Function('bitbag_cms_render_section_pages', [$this, 'renderSectionPages'], ['is_safe' => ['html']]), |
|
|
|
|
|
|
49
|
|
|
]; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function renderSectionPages(string $sectionCode, ?string $template = null): string |
|
53
|
|
|
{ |
|
54
|
|
|
$channelCode = $this->channelContext->getChannel()->getCode(); |
|
55
|
|
|
$section = $this->sectionRepository->findOneByCode($sectionCode, $this->localeContext->getLocaleCode()); |
|
56
|
|
|
$pages = $this->pageRepository->createShopListQueryBuilder($sectionCode, $channelCode)->getQuery()->getResult(); |
|
|
|
|
|
|
57
|
|
|
|
|
58
|
|
|
return $this->templatingEngine->render($template ?? '@BitBagSyliusCmsPlugin/Shop/Section/_pagesBySection.html.twig', [ |
|
59
|
|
|
'section' => $section, |
|
60
|
|
|
'pages' => $pages, |
|
61
|
|
|
]); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|