custom/plugins/AcrisFaqCS/src/Storefront/Controller/FaqController.php line 42

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Acris\Faq\Storefront\Controller;
  3. use Acris\Faq\Components\Faq\Exception\FaqIdNotFoundException;
  4. use Acris\Faq\Components\Faq\Exception\FaqNotFoundException;
  5. use Acris\Faq\Core\Content\Cms\DataResolver\Element\DummyClasses\SalesChannelCmsPageDummyLoader;
  6. use Acris\Faq\Custom\FaqDefinition;
  7. use Acris\Faq\Storefront\Page\FaqDetail\FaqDetailPageLoader;
  8. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\EntityResolverContext;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  10. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  11. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  12. use Shopware\Storefront\Controller\StorefrontController;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. /**
  17. * @RouteScope(scopes={"storefront"})
  18. */
  19. class FaqController extends StorefrontController
  20. {
  21. private FaqDetailPageLoader $faqDetailPageLoader;
  22. private SalesChannelCmsPageDummyLoader $salesChannelCmsPageDummyLoader;
  23. private FaqDefinition $faqDefinition;
  24. public function __construct(
  25. FaqDetailPageLoader $faqDetailPageLoader,
  26. SalesChannelCmsPageDummyLoader $salesChannelCmsPageDummyLoader,
  27. FaqDefinition $faqDefinition
  28. )
  29. {
  30. $this->faqDetailPageLoader = $faqDetailPageLoader;
  31. $this->salesChannelCmsPageDummyLoader = $salesChannelCmsPageDummyLoader;
  32. $this->faqDefinition = $faqDefinition;
  33. }
  34. /**
  35. * @Route("/faq/detail/{faqId}", name="frontend.faq.detail", options={"seo"="false"}, methods={"GET"}, defaults={"XmlHttpRequest": true})
  36. */
  37. public function detail(string $faqId, Request $request, SalesChannelContext $salesChannelContext): Response
  38. {
  39. if (!$faqId) {
  40. throw new FaqIdNotFoundException();
  41. }
  42. $page = $this->faqDetailPageLoader->load($faqId, $request, $salesChannelContext);
  43. if($page->getFaq()->getCmsPageId()){
  44. $cmsPages = $this->salesChannelCmsPageDummyLoader->load(
  45. $request,
  46. new Criteria([$page->getFaq()->getCmsPageId()]),
  47. $salesChannelContext,
  48. null,
  49. new EntityResolverContext($salesChannelContext, $request, $this->faqDefinition, $page->getFaq()));
  50. if($cmsPages){
  51. $page->getFaq()->setCmsPage($cmsPages->first());
  52. }
  53. }
  54. if(!empty($page)){
  55. return $this->renderStorefront('@Storefront/storefront/page/faq-detail/acris-faq-detail.html.twig', ['page' => $page]);
  56. }
  57. throw new FaqNotFoundException();
  58. }
  59. }