Deprecated: Symfony\Component\Translation\t(): Implicitly marking parameter $domain as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/translation/Resources/functions.php on line 18

Deprecated: Symfony\Component\Dotenv\Dotenv::loadEnv(): Implicitly marking parameter $envKey as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/dotenv/Dotenv.php on line 110

Deprecated: Symfony\Component\Runtime\GenericRuntime::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/GenericRuntime.php on line 89

Deprecated: Symfony\Component\Runtime\RuntimeInterface::getResolver(): Implicitly marking parameter $reflector as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/runtime/RuntimeInterface.php on line 26

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $argv as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\ArgvInput::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/ArgvInput.php on line 46

Deprecated: Symfony\Component\Console\Input\Input::__construct(): Implicitly marking parameter $definition as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/t/taurushr/vendor/symfony/console/Input/Input.php on line 36

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 58

Deprecated: Constant E_STRICT is deprecated in /var/www/html/t/taurushr/vendor/symfony/error-handler/ErrorHandler.php on line 76
Symfony Profiler

src/Controller/MenuDefaultController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Menu;
  4. use App\Entity\MenuItems;
  5. use App\Entity\Service;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\HttpFoundation\Response;
  10. class MenuDefaultController extends AbstractController
  11. {
  12.     public function __construct(protected EntityManagerInterface $em) {}
  13.     public function fetchMenu(Request $request$identifier$currentUrl$renderUL true)
  14.     {
  15.         $locale $request->getLocale();
  16.         $menu $this->em->getRepository(Menu::class)->findOneBy(['identifier' => $identifier]);
  17.         if (null === $menu) {
  18.             return new Response('');
  19.             // throw $this->createNotFoundException('PCGC: The menu \'' . $indentifier . '\' does not exist');
  20.         }
  21.         return $this->render('@theme/common/menu.html.twig', [
  22.             'menu' => $this->getMenuStructure($locale$menu),
  23.             'currentUrl' => $currentUrl,
  24.         ]);
  25.     }
  26.     public function hasMenuChildren($menuData$id)
  27.     {
  28.         return array_filter($menuData, fn ($var) => $var['menu_parent_id'] == $id);
  29.     }
  30.     private function getMenuStructure($locale$menu)
  31.     {
  32.         $menuData $menu->getMenuItems();
  33.         $items = [];
  34.         foreach ($menuData as $menuItem) {
  35.             $page $menuItem->getPageId();
  36.             if (null != $page) {
  37.                 $navTitle $page->getNavTitle();
  38.                 $slug $page->getSlug();
  39.             } else {
  40.                 $navTitle $menuItem->getNameOverride();
  41.                 $slug $menuItem->getUrlOverride();
  42.             }
  43.             // no navtitle override for translations
  44.             if ('en' == $locale && '' != $menuItem->getNameOverride()) {
  45.                 $navTitle $menuItem->getNameOverride();
  46.             }
  47.             $items[] = [
  48.                 'menu_item_id' => $menuItem->getMenuItemId(),
  49.                 'navtitle' => $navTitle,
  50.                 'slug' => $this->fixSlug($slug),
  51.                 'isdynamic' => $menuItem->getIsdynamic(),
  52.                 'url_override' => $menuItem->getUrlOverride() ? $this->fixSlug($menuItem->getUrlOverride()) : null,
  53.                 'dynamicentity' => $menuItem->getDynamicentity(),
  54.                 'new_window' => $menuItem->getNewwindow(),
  55.                 'menu_parent_id' => $menuItem->getMenuParentId(),
  56.             ];
  57.         }
  58.         foreach ($items as $key => $item) {
  59.             if (!$item['isdynamic']) {
  60.                 continue;
  61.             }
  62.             $items[$key]['dynamic_items'] = $this->getDynamicItems($item);
  63.         }
  64.         $menu $this->hasMenuChildren($items0);
  65.         foreach ($menu as $key => $item) {
  66.             $menu[$key]['children'] = $this->hasMenuChildren($items$item['menu_item_id']);
  67.             foreach ($menu[$key]['children'] as $key2 => $item2) {
  68.                 $menu[$key]['children'][$key2]['children'] = $this->hasMenuChildren($items$item2['menu_item_id']);
  69.                 foreach ($menu[$key]['children'][$key2]['children'] as $key3 => $item3) {
  70.                     $menu[$key]['children'][$key2]['children'][$key3]['children'] = $this->hasMenuChildren($items$item3['menu_item_id']);
  71.                 }
  72.             }
  73.         }
  74.         return $menu;
  75.     }
  76.     private function getDynamicItems($item)
  77.     {
  78.         $dynamicItems = [];
  79.         $bundleEntity '\\' str_replace(':''\\Entity\\', (string) $item['dynamicentity']);
  80.         $dyn_manu_items = [];
  81.         if ($item['dynamicentity'] == 'App:Service' && $item['menu_parent_id'] !== null) {
  82.             $parent $this->em->getRepository(MenuItems::class)->findOneBy(['menu_item_id' => $item['menu_parent_id']]);
  83.             if ($parent) {
  84.                 // strip all whitespace convert to lowercse and check it contains employee or employer
  85.                 $linkTitle strtolower(str_replace(' '''$parent->getNameOverride()));
  86.                 if (str_contains($linkTitle'employee')) {
  87.                     $dyn_manu_items $this->em->getRepository($bundleEntity)->findBy(['active' => 1'deleted' => 0'category' => 2'show_on_menu' => true]);
  88.                 } elseif (str_contains($linkTitle'employer')) {
  89.                     $dyn_manu_items $this->em->getRepository($bundleEntity)->findBy(['active' => 1'deleted' => 0'category' => 1'show_on_menu' => true]);
  90.                 }
  91.             }
  92.         }
  93.         if (empty($dyn_manu_items)) {
  94.             $dyn_manu_items $this->em->getRepository($bundleEntity)->findBy(['active' => 1'deleted' => 0]);
  95.         }
  96.         $possibleTitles = ['getTitle''getName''getHeadline''getHeading''getMetaTitle'];
  97.         foreach ($dyn_manu_items as $dyn_manu_item) {
  98.             $dyn_title '';
  99.             // check to ensure that the get<Whatever> fucntion exists on the entity
  100.             foreach ($possibleTitles as $title) {
  101.                 if (method_exists($dyn_manu_item$title)) {
  102.                     $dyn_title call_user_func([$dyn_manu_item$title]);
  103.                     break;
  104.                 }
  105.             }
  106.             $url $item['url_override'].'/'.$dyn_manu_item->getSlug();
  107.             $dynamicItems[] = [
  108.                 'navtitle' => $dyn_title,
  109.                 'slug' => $url,
  110.             ];
  111.         }
  112.         return $dynamicItems;
  113.     }
  114.     private function fixSlug($slug)
  115.     {
  116.         // some slugs will be prefixed with '/' while other may not (i.e db or custom) - so add them if they need them
  117.         if (str_starts_with((string) $slug'http')) {
  118.             return $slug;
  119.         }
  120.         if (str_starts_with((string) $slug'/')) {
  121.             $slug ltrim((string) $slug'/');
  122.         }
  123.         $slug ltrim((string) $slug'/');
  124.         return '/'.$slug;
  125.     }
  126. }