src/Aqarmap/Bundle/ListingBundle/EventListener/ConfigureMenuEventSubscriber.php line 98
<?phpnamespace Aqarmap\Bundle\ListingBundle\EventListener;use Aqarmap\Bundle\FeatureToggleBundle\Service\FeatureToggleManager;use Aqarmap\Bundle\ListingBundle\Constant\LocationLevels;use Aqarmap\Bundle\ListingBundle\Entity\Listing;use Aqarmap\Bundle\ListingBundle\EventListener\MenuBuilder\RenderSideBar;use Aqarmap\Bundle\ListingBundle\Twig\ListingExtension;use Aqarmap\Bundle\MainBundle\Event\ConfigureMenuEvent;use Aqarmap\Bundle\MainBundle\Service\Setting;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\EventDispatcher\EventSubscriberInterface;use Symfony\Component\HttpFoundation\RequestStack;use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;use Symfony\Contracts\Translation\TranslatorInterface;class ConfigureMenuEventSubscriber implements EventSubscriberInterface{/*** List of roles.** @var array*/protected $roles = ['ROLE_FREE_LISTING','ROLE_PROJECTS','ROLE_INCREASING_LISTINGS','ROLE_PAID_LISTING','ROLE_ADMIN_ACTIVITIES','ROLE_WEBMASTER','ROLE_ACCESS_TO_ADMIN_LEADS','ROLE_MARKETING','ROLE_CRM','ROLE_CUSTOMER_PROFILING','ROLE_SUPER_ADMIN','ROLE_LEADS_STATISTICS','ROLE_PENDING_FEATURING_LISTING','ROLE_LOCATIONS','ROLE_PUBLISHED_LISTINGS_COUNT','ROLE_RELIST_LISTING','ROLE_SCRAPPED_LISTING','ROLE_ACTIVE_CUSTOMER',];/*** Translator instance.*/protected $translator;public function __construct(TranslatorInterface $translator,private readonly FeatureToggleManager $featureToggleManager,private readonly Setting $setting,private readonly AuthorizationCheckerInterface $authorizationChecker,private readonly EntityManagerInterface $entityManager,private readonly ListingExtension $listingExtension,private readonly RequestStack $requestStack,) {$this->translator = $translator;}public function onAdminSidebarMenuConfigure(ConfigureMenuEvent $event): void{$userRole = $this->authorizationChecker;$renderSideBar = (new RenderSideBar($this->featureToggleManager, $this->authorizationChecker))->setMenu($event->getMenu())->setTranslator($this->translator);foreach ($this->roles as $role) {if ($userRole->isGranted($role)) {$fn = 'has'.$this->snakeToCamel($role);$renderSideBar->$fn();}}}public function onMainNavbarMenuConfigure(ConfigureMenuEvent $event): void{$menu = $event->getMenu();if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) {// My Listings$menu->addChild('my_listings', ['route' => 'aqarmap_listing_default_mylistings'])->setLabel($this->translator->trans('layout.my_listings.title'))->setExtra('position', 50);// List your property$menu->addChild('add_listing', ['route' => 'listing_initialize'])->setLabel($this->translator->trans('layout.add_listing'))->setExtra('position', 40);}}public function onBreadcrumbConfigure(ConfigureMenuEvent $event): void{$menu = $event->getMenu();$listing = $this->getRequest()->attributes->get('listing');if ($listing instanceof Listing) {$this->getRequest()->attributes->set('section', $listing->getSection());$this->getRequest()->attributes->set('propertyType', $listing->getPropertyType());$this->getRequest()->attributes->set('location', $listing->getLocation());}if ($section = $this->getRequest()->attributes->get('section')) {// If not searchable section, than it's premium section (Projects)$premium_section = !$section->getSearchable() || ($listing instanceof Listing && $listing->getParent() instanceof Listing);// Search linksif (($propertyType = $this->getRequest()->attributes->get('propertyType')) && !$premium_section) {$menu->addChild($section->getSlug(), ['route' => 'property_type_search','routeParameters' => ['section_slug' => $section->getSlug(),'property_type_slug' => 'property-type',],])->setAttribute('title', $this->translator->trans('listing.quickLinks_title_section', ['%section%' => $section->getTitle(),]))->setLabel($this->translator->trans('listing.quickLinks_title_section', ['%section%' => $section->getTitle(),]));$menu->addChild($propertyType->getSlug(), ['route' => 'property_type_search','routeParameters' => ['section_slug' => $section->getSlug(),'property_type_slug' => $propertyType->getSlug(),],])->setAttribute('title', $this->translator->trans('listing.quickLinks_title_wo_location', ['%property_type%' => $propertyType->getTitle(),'%section%' => $section->getTitle(),]))->setLabel($propertyType->getTitle());// Locationsif ($location = $this->getRequest()->attributes->get('location')) {/** @var \Aqarmap\Bundle\ListingBundle\Entity\LocationRepository $locationRepo */$locationRepo = $this->entityManager->getRepository(\Aqarmap\Bundle\ListingBundle\Entity\Location::class);foreach ($locationRepo->getPath($location) as $treeLocation) {// Skip non-searchable locationsif ($treeLocation->getLevel() > LocationLevels::MAX_LEVEL) {continue;}$menu->addChild($treeLocation->getSlug(), ['route' => 'search','routeParameters' => ['section_slug' => $section->getSlug(),'property_type_slug' => $propertyType->getSlug(),'location_slug' => $treeLocation->getSlug(),],])->setAttribute('title', $this->translator->trans('listing.quickLinks_title', ['%property_type%' => $propertyType->getTitle(),'%section%' => $section->getTitle(),'%location%' => $treeLocation->getTitle(),]))->setLabel($treeLocation->getTitle());}}} elseif ($listing = $this->getRequest()->attributes->get('listing')) {$menu->addChild('section', ['route' => 'compound_search'])->setAttribute('title', $this->translator->trans('listing.quickLinks_title_section', ['%section%' => $section->getTitle(),]))->setLabel($section->getTitle());/** @var \Aqarmap\Bundle\ListingBundle\Entity\CompoundLocation $compoundLocation */if ($compoundLocation = $listing->getCompoundLocation()) {$compoundsLabel = $this->translator->trans('layout.location_compound',['%location%' => $compoundLocation]);if ('SA' == $this->setting->getSetting('general', 'country')) {$compoundsLabel = $this->translator->trans('layout.location_project',['%location%' => $compoundLocation]);}$menu->addChild('section_location', ['route' => 'compound_search_with_location','routeParameters' => ['location' => $compoundLocation->getSlug(),],])->setLabel($compoundsLabel);}}}$listingExtension = $this->listingExtension;if ($listing && $listing->getParent()) {// With Slugif ($listing->getParent()->getSlug()) {$parentRoute = ['route' => 'listing_slug','routeParameters' => ['id' => $listing->getParent()->getId(),'slug' => $listing->getParent()->getSlug(),],'extras' => ['safe_label' => true,],];} // Without Slugelse {$parentRoute = ['route' => 'listing_view', 'routeParameters' => ['id' => $listing->getParent()->getId(),]];}$menu->addChild($listing->getParent()->getId(), $parentRoute)->setLabel($listingExtension->fixArabicNumbers($listing->getParent()->getTitle()));}if ($listing) {// With Slugif ($listing->getSlug()) {$listingRoute = ['route' => 'listing_slug','routeParameters' => ['id' => $listing->getId(),'slug' => $listing->getSlug(),],'extras' => ['safe_label' => true,],];} // Without Slugelse {$listingRoute = ['route' => 'listing_view', 'routeParameters' => ['id' => $listing->getId(),]];}$menu->addChild($listing->getId(), $listingRoute)->setLabel($listingExtension->fixArabicNumbers($listing->getTitle()));} elseif ($section = $this->getRequest()->attributes->get('section')) {$translatedTitle = $this->translator->trans('listing.quickLinks_title_section', ['%section%' => $section->getTitle(),]);$menu->addChild($section->getSlug(), ['route' => 'property_type_search','routeParameters' => ['section_slug' => $section->getSlug(),'property_type_slug' => 'property-type',],])->setAttribute('title', $translatedTitle)->setLabel($translatedTitle);}}public function getRequest(){return $this->requestStack->getCurrentRequest();}/*** Convert underscore_strings to camelCase.** @param string $str** @return string*/private function snakeToCamel($str){return str_replace(' ', '', ucwords(str_replace('_', ' ', strtolower($str))));}/*** @return array<string, mixed>*/public static function getSubscribedEvents(): array{return [ConfigureMenuEvent::ADMIN_SIDEBAR_CONFIGURE => 'onAdminSidebarMenuConfigure','aqarmap.main.breadcrumb_configure' => 'onBreadcrumbConfigure',];}}