src/Service/LegacyControllerService.php line 30

Open in your IDE?
  1. <?php
  2. namespace App\Service;
  3. use App\Application\Service\Customer\CustomerStatsService;
  4. use App\Application\Service\Helper\LinkGenerator;
  5. use App\Application\Service\Session\SessionService;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Twig\Environment;
  8. class LegacyControllerService
  9. {
  10.     private CustomerStatsService $customerStatsService;
  11.     private SessionService $sessionService;
  12.     private Environment $twig;
  13.     private LinkGenerator $linkGenerator;
  14.     public function __construct(
  15.         CustomerStatsService $customerStatsService,
  16.         SessionService $sessionService,
  17.         Environment $twig,
  18.         LinkGenerator $linkGenerator
  19.     ) {
  20.         $this->customerStatsService $customerStatsService;
  21.         $this->sessionService $sessionService;
  22.         $this->twig $twig;
  23.         $this->linkGenerator $linkGenerator;
  24.     }
  25.     public function getHtmlFromLegacyController(\Controller $legacyController): string
  26.     {
  27.         $headData $legacyController->head();
  28.         if (null === $headData || $legacyController->getDisplay_only_view()) {
  29.             $html $legacyController->display();
  30.             return new Response($html);
  31.         }
  32.         $customerStats $this->customerStatsService->getCustomerStatsId();
  33.         $userId $customerStats $customerStats->getId() : null;
  34.         $currentUrl $this->getCurrentUrl($headData);
  35.         $renderedTemplateData = [
  36.             'bodyHtml' => $legacyController->display(true),
  37.             'headHtml' => $this->twig->render('front/base/legacy_head.html.twig', [
  38.                 'data' => $headData,
  39.                 'current_url' => $currentUrl,
  40.                 'dataLayerUserData' => [
  41.                     'userId' => $userId,
  42.                     'pageName' => $this->sessionService->get('url'),
  43.                 ],
  44.             ]),
  45.             'shopMenuHtml' => $legacyController->isShopMenu() ? $legacyController->mainNav() : null,
  46.             'footerJs' => $legacyController->prepareJs(true),
  47.         ];
  48.         $renderedTemplate $this->twig->render(
  49.             'front/base/base_'.($legacyController->isShopMenu() ? 'shop' 'corporate').'_legacy.html.twig',
  50.             $renderedTemplateData
  51.         );
  52.         $this->sessionService->deleteFlashData();
  53.         return $renderedTemplate;
  54.     }
  55.     public function getCurrentUrl(\Partial $headData): string
  56.     {
  57.         $currentUrl '';
  58.         if (!empty($headData->current_url_fb)) {
  59.             return $headData->current_url_fb;
  60.         }
  61.         if (!empty($headData->current_url)) {
  62.             return $this->linkGenerator->getCurrentLink(
  63.                 $headData->current_url,
  64.                 $this->sessionService->getLocaleId()
  65.             );
  66.         }
  67.         return $currentUrl;
  68.     }
  69. }