src/Flexy/FrontBundle/EventSubscriber/HookSubscriber.php line 33

  1. <?php
  2. // src/EventSubscriber/HookSubscriber.php
  3. namespace App\Flexy\FrontBundle\EventSubscriber;
  4. use App\Entity\Settings;
  5. use App\Flexy\FrontBundle\Entity\Menu;
  6. use App\Flexy\FrontBundle\Entity\Page;
  7. use App\Flexy\FrontBundle\Service\FlexyFrontProvider;
  8. use App\Flexy\FrontBundle\Service\HookService;
  9. use Doctrine\Persistence\ManagerRegistry;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\Event\RequestEvent;
  12. class HookSubscriber implements EventSubscriberInterface
  13. {
  14.     private HookService $hookService;
  15.     private ManagerRegistry $doctrine;
  16.     public function __construct(HookService $hookService,ManagerRegistry $doctrine,private readonly FlexyFrontProvider $flexyFrontProvider)
  17.     {
  18.         $this->hookService $hookService;
  19.         $this->doctrine $doctrine;
  20.     }
  21.     public static function getSubscribedEvents()
  22.     {
  23.         return [
  24.             'kernel.request' => 'onKernelRequest'// Adjust this to suit your needs
  25.         ];
  26.     }
  27.     public function onKernelRequest(RequestEvent $requestEvent)
  28.     {
  29.         if (!$requestEvent->isMainRequest()) {
  30.             return; // Ensure this only runs for the main request
  31.         }
  32.         
  33.         
  34.         // Example: Registering a hook to render a Twig template
  35.         // $this->hookService->renderTwig('header_left', '@Flexy/FrontBundle/Themes/Default/templates/web-themes/flexy-shop/partials/header/_left.html.twig', [], 10);
  36.         // Example: Registering a hook to render a Twig template
  37.         $settings $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
  38.         if($settings->getAssetFolderName() !=  "Default" ){
  39.             return;
  40.         }
  41.         $this->hookService->register('home_before_main_content', function() {
  42.             return `
  43.     
  44.         
  45.     
  46.         <!-- About Us -->
  47.         <div class="container my-5">
  48.             <h2 class="text-center mb-4">About Us</h2>
  49.             <div class="row">
  50.                 <div class="col-md-6">
  51.                     <img src="https://placehold.co/500x300" class="img-fluid" alt="About Us">
  52.                 </div>
  53.                 <div class="col-md-6">
  54.                     <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore
  55.                         et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut
  56.                         aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse
  57.                         cillum dolore eu fugiat nulla pariatur.</p>
  58.                 </div>
  59.             </div>
  60.         </div>
  61. `;
  62.         }, 0);
  63.         
  64.          $this->hookService->register('footer', function() {
  65.             return ' <div class="container text-center p-5">
  66.             <p>&copy; 2024 Flexy Platform. All rights reserved.</p>
  67.         </div>';
  68.          },0);
  69.         $currentWebsiteTheme $settings->getWebsiteTheme()->getCode(); 
  70.          
  71.         $this->hookService->register('header_left', function(){
  72.             $settings $this->doctrine->getManager()->getRepository(Settings::class)->findOneBy(["code"=>"main"]);
  73.             $title =  $settings->getLogo() ? '<a href="/" class="logo"><img src="/uploads/default/'.$settings->getLogo().'" /></a>' '<h2>Your logo</h2>';
  74.             return '<div class="pt-2">
  75.             '.$title.'            
  76.             </div>';
  77.         }, 0);
  78.         $this->hookService->register('header_middle', function(){
  79.             $menu $this->doctrine->getManager()->getRepository(Menu::class)->findOneBy(["isMainMenu"=>true]);
  80.             $menuHTML $this->flexyFrontProvider->getRendredMenu($menu);
  81.             
  82.             return $menuHTML;
  83.         }, 0);
  84.         $this->hookService->renderTwig('header_right''@Flexy/FrontBundle/Themes/Default/templates/web-themes/'.$currentWebsiteTheme.'/partials/header/_right.html.twig', [], 0);
  85.         // Widgets Hooks Start
  86.         $widgets $this->doctrine->getManager()->getRepository(Page::class)->findBy(["type"=>"widget"]);
  87.         foreach($widgets as $singleWidget){
  88.             if($singleWidget->getFrontHook()){
  89.                 $this->hookService->renderRoute(
  90.                     $singleWidget->getFrontHook(),
  91.                     'widget_single_page',
  92.                     ["slug"=>$singleWidget->getSlug()],
  93.                     (int)$singleWidget->getFrontHookPriority(),
  94.                     $singleWidget->getSlug()
  95.                 );
  96.             }
  97.            
  98.         }
  99.        
  100.     }
  101. }