src/Twig/TwigExtension.php line 1384

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: nico.filzmoser
  5.  * Date: 26.03.18
  6.  * Time: 14:12
  7.  */
  8. namespace App\Twig;
  9. use App\Service\AimsService;
  10. use App\Service\AnnouncementService;
  11. use App\Service\CategoryConfigurationService;
  12. use App\Service\DocumentService;
  13. use App\Service\LinkService;
  14. use App\Service\OverviewService;
  15. use App\Service\MenuService;
  16. use App\Service\PriceRequestProductsService;
  17. use App\Service\ScienceCenterService;
  18. use App\Service\SearchService;
  19. use App\Service\ServiceStationLocatorService;
  20. use App\Service\LocationService;
  21. use App\Service\LabelService;
  22. use App\Service\FaqService;
  23. use App\Service\EventService;
  24. use App\Service\AccessoryService;
  25. use App\Service\TeaserIncludeService;
  26. use App\Service\User\UserService;
  27. use App\Service\VideoTutorialService;
  28. use App\Helper\StoryblokHelper;
  29. use App\Service\NewsroomService;
  30. use App\Service\PromotionService;
  31. use App\Service\WidgetService;
  32. use App\Service\DosingCalculatorService;
  33. use App\Service\SAGEApiService;
  34. use App\Service\RedirectService;
  35. use Exception;
  36. use Psr\Log\LoggerInterface;
  37. use Storyblok;
  38. use Symfony\Component\HttpFoundation\RequestStack;
  39. use Twig\Extension\AbstractExtension;
  40. use Twig\TwigFilter;
  41. use Twig\TwigFunction;
  42. use Parsedown;
  43. class TwigExtension extends AbstractExtension
  44. {
  45.     private $storyblok;
  46.     private $fontCacheKey;
  47.     private $googleAnalyticsKey;
  48.     private $googleSiteVerificationContent;
  49.     private $cacheVersion;
  50.     private $requestStack;
  51.     private $logger;
  52.     private $projectDir;
  53.     private $availableLanguages;
  54.     private $domain;
  55.     private $micrositeNameMap;
  56.     /**
  57.      * @var SearchService
  58.      */
  59.     private $searchService;
  60.     /**
  61.      * @var ServiceStationLocatorService
  62.      */
  63.     private $serviceStationLocatorService;
  64.     /**
  65.      * @var LabelService
  66.      */
  67.     private $labelService;
  68.     /**
  69.      * @var FaqService
  70.      */
  71.     private $faqService;
  72.     /**
  73.      * @var EventService
  74.      */
  75.     private $eventService;
  76.     /**
  77.      * @var string
  78.      */
  79.     private $datareporterUrl;
  80.     /**
  81.      * @var OverviewService
  82.      */
  83.     private $overviewService;
  84.     /**
  85.      * @var AccessoryService
  86.      */
  87.     private $accessoryService;
  88.     /**
  89.      * @var TeaserIncludeService
  90.      */
  91.     private $teaserIncludeService;
  92.     /**
  93.      * @var DocumentService
  94.      */
  95.     private $documentService;
  96.     /**
  97.      * @var LocationService
  98.      */
  99.     private $locationService;
  100.     /**
  101.      * @var VideoTutorialService
  102.      */
  103.     private $videoTutorialService;
  104.     /**
  105.      * @var UserService
  106.      */
  107.     private $userService;
  108.     /**
  109.      * @var MenuService
  110.      */
  111.     private $menuService;
  112.     /**
  113.      * @var PriceRequestProductsService
  114.      */
  115.     private $priceRequestProductsService;
  116.     /**
  117.      * @var ScienceCenterService
  118.      */
  119.     private $scienceCenterService;
  120.     /**
  121.      * @var CategoryConfigurationService
  122.      */
  123.     private $categoryConfigService;
  124.     /**
  125.      * @var AnnouncementService
  126.      */
  127.     private $announcementService;
  128.     /**
  129.      * @var StoryblokHelper
  130.      */
  131.     private $storyblokHelper;
  132.     /**
  133.      * @var LinkService
  134.      */
  135.     private $linkService;
  136.     private $aimsService;
  137.     /**
  138.      * @var array
  139.      */
  140.     private $recaptchaConfig;
  141.     /**
  142.      * @var NewsroomService;
  143.      */
  144.     private $newsroomService;
  145.     /**
  146.      * @var string
  147.      */
  148.     private $newsroomRefreshLanguages;
  149.     /**
  150.      * @var array
  151.      */
  152.     private $shopDomains;
  153.     /**
  154.      * @var string
  155.      */
  156.     private $datareporterUrlActivationCode;
  157.     /**
  158.      * @var WidgetService;
  159.      */
  160.     private $widgetService;
  161.     /**
  162.      * @var PromotionService;
  163.      */
  164.     private $promotionService;
  165.     /**
  166.      * @var DosingCalculatorService;
  167.      */
  168.     private $dosingCalculatorService;
  169.     /**
  170.      * @var SAGEApiService;
  171.      */
  172.     private $sageApiService;
  173.     /**
  174.      * @var RedirectService;
  175.      */
  176.     private $redirectService;
  177.     /**
  178.      * @var array
  179.      */
  180.     private $countryLanguageMapping;
  181.     public function __construct(
  182.         string $fontCacheKey,
  183.         string $googleAnalyticsId,
  184.         string $cacheVersion,
  185.         array $recaptchaConfig,
  186.         string $projectDir,
  187.         string $availableLanguages,
  188.         string $domain,
  189.         string $mapiToken,
  190.         string $spaceId,
  191.         string $googleSiteVerificationContent,
  192.         array $micrositeNameMap,
  193.         string $newsroomRefreshLanguages,
  194.         string $datareporterUrl,
  195.         string $datareporterUrlActivationCode,
  196.         array $shopDomains,
  197.         array $countryLanguageMapping,
  198.         UserService $userService,
  199.         SearchService $searchService,
  200.         ServiceStationLocatorService $serviceStationLocatorService,
  201.         VideoTutorialService $videoTutorialService,
  202.         DocumentService $documentService,
  203.         LocationService $locationService,
  204.         CategoryConfigurationService $categoryConfigurationService,
  205.         MenuService $menuService,
  206.         PriceRequestProductsService $priceRequestProductsService,
  207.         LabelService $labelService,
  208.         ScienceCenterService $scienceCenterService,
  209.         FaqService $faqService,
  210.         EventService $eventService,
  211.         AccessoryService $accessoryService,
  212.         TeaserIncludeService $teaserIncludeService,
  213.         OverviewService $overviewService,
  214.         Storyblok\Client $storyblok,
  215.         LoggerInterface $logger,
  216.         RequestStack $requestStack,
  217.         AnnouncementService $announcementService,
  218.         StoryblokHelper $storyblokHelper,
  219.         LinkService $linkService,
  220.         AimsService $aimsService,
  221.         NewsroomService $newsroomService,
  222.         WidgetService $widgetService,
  223.         PromotionService $promotionService,
  224.         DosingCalculatorService $dosingCalculatorService,
  225.         SAGEApiService $sageApiService,
  226.         RedirectService $redirectService
  227.     ) {
  228.         $this->fontCacheKey $fontCacheKey;
  229.         $this->googleAnalyticsId $googleAnalyticsId;
  230.         $this->cacheVersion $cacheVersion;
  231.         $this->projectDir $projectDir;
  232.         $this->availableLanguages explode('|'$availableLanguages);
  233.         $this->domain $domain;
  234.         $this->mapiToken $mapiToken;
  235.         $this->spaceId $spaceId;
  236.         $this->googleSiteVerificationContent $googleSiteVerificationContent;
  237.         $this->countryLanguageMapping $countryLanguageMapping;
  238.         $this->userService $userService;
  239.         $this->accessoryService $accessoryService;
  240.         $this->teaserIncludeService $teaserIncludeService;
  241.         $this->videoTutorialService $videoTutorialService;
  242.         $this->overviewService $overviewService;
  243.         $this->faqService $faqService;
  244.         $this->eventService $eventService;
  245.         $this->labelService $labelService;
  246.         $this->scienceCenterService $scienceCenterService;
  247.         $this->searchService $searchService;
  248.         $this->serviceStationLocatorService $serviceStationLocatorService;
  249.         $this->documentService $documentService;
  250.         $this->locationService $locationService;
  251.         $this->categoryConfigService $categoryConfigurationService;
  252.         $this->menuService $menuService;
  253.         $this->priceRequestProductsService $priceRequestProductsService;
  254.         $this->storyblok $storyblok;
  255.         $this->announcementService $announcementService;
  256.         $this->storyblokHelper $storyblokHelper;
  257.         $this->linkService $linkService;
  258.         $this->datareporterUrl $datareporterUrl;
  259.         $this->datareporterUrlActivationCode $datareporterUrlActivationCode;
  260.         $this->shopDomains $shopDomains;
  261.         $this->logger $logger;
  262.         $this->requestStack $requestStack;
  263.         $this->micrositeNameMap $micrositeNameMap;
  264.         $this->aimsService $aimsService;
  265.         $this->recaptchaConfig $recaptchaConfig;
  266.         $this->newsroomService $newsroomService;
  267.         $this->newsroomRefreshLanguages $newsroomRefreshLanguages;
  268.         $this->widgetService $widgetService;
  269.         $this->promotionService $promotionService;
  270.         $this->dosingCalculatorService $dosingCalculatorService;
  271.         $this->sageApiService $sageApiService;
  272.         $this->redirectService $redirectService;
  273.     }
  274.     public function getFilters()
  275.     {
  276.         return [
  277.             new TwigFilter("version", [$this"version"]),
  278.             new TwigFilter("removeNbsp", [$this"removeNbsp"]),
  279.             new TwigFilter("markdown", [$this"markdown"], ["is_safe" => ["html"]])
  280.         ];
  281.     }
  282.     public function getFunctions()
  283.     {
  284.         return [
  285.             new TwigFunction("getCanonical", [$this"getCanonical"]),
  286.             new TwigFunction("getFontCacheKey", [$this"getFontCacheKey"]),
  287.             new TwigFunction("getGoogleAnalyticsId", [$this"getGoogleAnalyticsId"]),
  288.             new TwigFunction("getMetaInfo", [$this"getMetaInfo"]),
  289.             new TwigFunction("getStoryBySlug", [$this"getStoryBySlug"]),
  290.             new TwigFunction("getStories", [$this"getStories"]),
  291.             new TwigFunction("image", [$this"image"]),
  292.             new TwigFunction("url", [$this"url"]),
  293.             new TwigFunction("sbUrl", [$this"sbUrl"]),
  294.             new TwigFunction("sbUrlByUuid", [$this"sbUrlByUuid"]),
  295.             new TwigFunction("sbUrlById", [$this"sbUrlById"]),
  296.             new TwigFunction("include_file", [$this"includeFile"]),
  297.             new TwigFunction("label", [$this"label"]),
  298.             new TwigFunction("getSkus", [$this"getSkus"]),
  299.             new TwigFunction("getFamilyPart", [$this"getFamilyPart"]),
  300.             new TwigFunction("familyUrl", [$this"familyUrl"]),
  301.             new TwigFunction("systemConf", [$this"systemConf"]),
  302.             new TwigFunction("getNewsletterOgInfoById", [$this"getNewsletterOgInfoById"]),
  303.             new TwigFunction("getSearchHeadersForResultsPage", [$this"getSearchHeadersForResultsPage"]),
  304.             new TwigFunction("getClosestRetailer", [$this"getClosestRetailer"]),
  305.             new TwigFunction("getCategory", [$this"getCategory"]),
  306.             new TwigFunction("overviewData", [$this"overviewData"]),
  307.             new TwigFunction("rindex", [$this"rindex"]),
  308.             new TwigFunction("generateBreadcrumb", [$this"generateBreadcrumb"]),
  309.             new TwigFunction("getAccessoriesOptions", [$this"getAccessoriesOptions"]),
  310.             new TwigFunction("getTeasersByUri", [$this"getTeasersByUri"]),
  311.             new TwigFunction("getAccessoriesByProductId", [$this"getAccessoriesByProductId"]),
  312.             new TwigFunction("uuid", [$this"uuid"]),
  313.             new TwigFunction("uniqid", [$this"uniqid"]),
  314.             new TwigFunction("documentInfo", [$this"documentInfo"]),
  315.             new TwigFunction("getVideoTutorialsByProductId", [$this"getVideoTutorialsByProductId"]),
  316.             new TwigFunction("isUserLoggedIn", [$this"isUserLoggedIn"]),
  317.             new TwigFunction("activateUser", [$this"activateUser"]),
  318.             new TwigFunction("isStudentUser", [$this"isStudentUser"]),
  319.             new TwigFunction("userFirstname", [$this"userFirstname"]),
  320.             new TwigFunction("getProductNavigation", [$this'getProductNavigation']),
  321.             new TwigFunction("getNavigation", [$this'getNavigation']),
  322.             new TwigFunction("getFAQsByProductId", [$this'getFAQsByProductId']),
  323.             new TwigFunction("getFAQsByApplicationArea", [$this'getFAQsByApplicationArea']),
  324.             new TwigFunction("getScienceCenterByProductId", [$this'getScienceCenterByProductId']),
  325.             new TwigFunction("getNextEvent", [$this'getNextEvent']),
  326.             new TwigFunction("getLeftNavigation", [$this'getLeftNavigation']),
  327.             new TwigFunction("getDocumentObject", [$this'getDocumentObject']),
  328.             new TwigFunction("getCurrentLocation", [$this'getCurrentLocation']),
  329.             new TwigFunction("getShopUrl", [$this'getShopUrl']),
  330.             new TwigFunction("getCurrentLatitude", [$this'getCurrentLatitude']),
  331.             new TwigFunction("getCurrentLongitude", [$this'getCurrentLongitude']),
  332.             new TwigFunction("setActiveNav", [$this'setActiveNav']),
  333.             new TwigFunction("getBackendPath", [$this'getBackendPath']),
  334.             new TwigFunction("getSitemap", [$this'getSitemap']),
  335.             new TwigFunction("getCountryContactData", [$this'getCountryContactData']),
  336.             new TwigFunction("getNews", [$this"getNews"]),
  337.             new TwigFunction("resetArrayKeys", [$this"resetArrayKeys"]),
  338.             new TwigFunction("isEditMode", [$this"isEditMode"]),
  339.             new TwigFunction("addTeaserName", [$this"addTeaserName"]),
  340.             new TwigFunction("getAllTeaserNamesFormatted", [$this"getAllTeaserNamesFormatted"]),
  341.             new TwigFunction("addNewsName", [$this"addNewsName"]),
  342.             new TwigFunction("getAllNewsNamesFormatted", [$this"getAllNewsNamesFormatted"]),
  343.             new TwigFunction("getStoryById", [$this"getStoryById"]),
  344.             new TwigFunction("getStoryByUuid", [$this"getStoryByUuid"]),
  345.             new TwigFunction("microtime", [$this"microtime"]),
  346.             new TwigFunction("getRefererLink", [$this"getRefererLink"]),
  347.             new TwigFunction("getLanguageSwitchLinks", [$this"getLanguageSwitchLinks"]),
  348.             new TwigFunction("getStudentNews", [$this"getStudentNews"]),
  349.             new TwigFunction("logErrorReferrer", [$this"logErrorReferrer"]),
  350.             new TwigFunction("getDomain", [$this"getDomain"]),
  351.             new TwigFunction("getVideoChannelUrl", [$this"getVideoChannelUrl"]),
  352.             new TwigFunction("getTeasersByUri", [$this"getTeasersByUri"]),
  353.             new TwigFunction("getTeaserByPath", [$this"getTeaserByPath"]),
  354.             new TwigFunction("getSpaceID", [$this"getSpaceID"]),
  355.             new TwigFunction("isStaticUserLoggedIn", [$this"isStaticUserLoggedIn"]),
  356.             new TwigFunction("getMAPIToken", [$this"getMAPIToken"]),
  357.             new TwigFunction("getBlogNews", [$this"getBlogNews"]),
  358.             new TwigFunction("getMicrositeNavigation", [$this"getMicrositeNavigation"]),
  359.             new TwigFunction("getRandomNumbers", [$this"getRandomNumbers"]),
  360.             new TwigFunction("getRecaptchaSitekey", [$this"getRecaptchaSitekey"]),
  361.             new TwigFunction("getToken", [$this"getToken"]),
  362.             new TwigFunction("getGoogleSiteVerificationContent", [$this"getGoogleSiteVerificationContent"]),
  363.             new TwigFunction("getAimsSteps", [$this"getAimsSteps"]),
  364.             new TwigFunction("getAimsStepIndexes", [$this"getAimsStepIndexes"]),
  365.             new TwigFunction("getAimsStepDisplayNames", [$this"getAimsStepDisplayNames"]),
  366.             new TwigFunction("loadExternalFile", [$this"loadExternalFile"]),
  367.             new TwigFunction("getGoogleRecaptchaSitekey", [$this"getGoogleRecaptchaSitekey"]),
  368.             new TwigFunction("getStudentsSourcefield", [$this"getStudentsSourcefield"]),
  369.             new TwigFunction("getCurrentEnv", [$this"getCurrentEnv"]),
  370.             new TwigFunction("getNewsroomArticles", [$this"getNewsroomArticles"]),
  371.             new TwigFunction("getNewsroomMainCategories", [$this"getNewsroomMainCategories"]),
  372.             new TwigFunction("getNewsroomMainCategoryByType", [$this"getNewsroomMainCategoryByType"]),
  373.             new TwigFunction("getNewsroomArticlesByFamilyId", [$this"getNewsroomArticlesByFamilyId"]),
  374.             new TwigFunction("getNewsroomArticlesByPath", [$this"getNewsroomArticlesByPath"]),
  375.             new TwigFunction("getNewsroomTags", [$this"getNewsroomTags"]),
  376.             new TwigFunction("getNewsroomTagTranslation", [$this"getNewsroomTagTranslation"]),
  377.             new TwigFunction("getNewsroomIntervalDateAgo", [$this"getNewsroomIntervalDateAgo"]),
  378.             new TwigFunction("getNewsroomPathByType", [$this"getNewsroomPathByType"]),
  379.             new TwigFunction("getNewsroomArticlesByType", [$this"getNewsroomArticlesByType"]),
  380.             new TwigFunction("isNewsroomRefreshEnabledForLanguage", [$this"isNewsroomRefreshEnabledForLanguage"]),
  381.             new TwigFunction("getUserProfile", [$this"getUserProfile"]),
  382.             new TwigFunction("formatDateByLocale", [$this"formatDateByLocale"]),
  383.             new TwigFunction("getNewsroomNewsWithFilter", [$this"getNewsroomNewsWithFilter"]),
  384.             new TwigFunction("getAboriginalCountryDatasources", [$this"getAboriginalCountryDatasources"]),
  385.             new TwigFunction("getDatareporterUrl", [$this"getDatareporterUrl"]),
  386.             new TwigFunction("getUserCountryCode", [$this"getUserCountryCode"]),
  387.             new TwigFunction("getDatasourceEntries", [$this"getDatasourceEntries"]),
  388.             new TwigFunction("getDatareporterActivationcodeUrl", [$this"getDatareporterActivationcodeUrl"]),
  389.             new TwigFunction("getAimsContentOverlayTabLinks", [$this"getAimsContentOverlayTabLinks"]),
  390.             new TwigFunction("getAimsColorByStep", [$this"getAimsColorByStep"]),
  391.             new TwigFunction("getProductConfiguratorAnswersHasImage", [$this"getProductConfiguratorAnswersHasImage"]),
  392.             new TwigFunction("getAimsStepsByStep", [$this"getAimsStepsByStep"]),
  393.             new TwigFunction("getAimsStepNumberByAnchorName", [$this"getAimsStepNumberByAnchorName"]),
  394.             new TwigFunction("getAlternatesByLocaleAndFamilyId", [$this"getAlternatesByLocaleAndFamilyId"]),
  395.             new TwigFunction("getWidgetByUid", [$this"getWidgetByUid"]),
  396.             new TwigFunction("getPromotionsCategories", [$this"getPromotionsCategories"]),
  397.             new TwigFunction("getPromotions", [$this"getPromotions"]),
  398.             new TwigFunction("getPromotionCategoryTranslation", [$this"getPromotionCategoryTranslation"]),
  399.             new TwigFunction("getPromotionCategoriesKeys", [$this"getPromotionCategoriesKeys"]),
  400.             new TwigFunction("getPromotionCategoryKey", [$this"getPromotionCategoryKey"]),
  401.             new TwigFunction("hasImageCorrectSize", [$this"hasImageCorrectSize"]),
  402.             new TwigFunction("getDosingCalculatorData", [$this"getDosingCalculatorData"]),
  403.             new TwigFunction("getJobById", [$this"getJobById"]),
  404.             new TwigFunction("isChatbubbleDisabled", [$this"isChatbubbleDisabled"]),
  405.             new TwigFunction("getJobs", [$this"getJobs"]),
  406.             new TwigFunction("getJobContactPersons", [$this"getJobContactPersons"]),
  407.             new TwigFunction("getEventsByType", [$this"getEventsByType"]),
  408.             new TwigFunction("getRedirectsTo", [$this"getRedirectsTo"])
  409.         ];
  410.     }
  411.     public function getRedirectsTo($url)
  412.     {
  413.         return $this->redirectService->getRedirectsTo($url);
  414.     }
  415.     public function getEventsByType($type)
  416.     {
  417.         return $this->newsroomService->getEventsByType($type);
  418.     }
  419.     public function getJobContactPersons($locale$contactPersonID)
  420.     {
  421.         $contactPersons = [];
  422.         if (!$contactPersonID) {
  423.             return $contactPersons;
  424.         }
  425.         try {
  426.             $categoryConfig $this->categoryConfigService->getByFamilyId($locale'/career/contactpersons');
  427.             $contactPersons $this->storyblok->getStories([
  428.                 'page' => '1',
  429.                 'per_page' => 1000,
  430.                 'starts_with' => ltrim($categoryConfig['seo_url'], '/')
  431.             ])->getBody()['stories'];
  432.             foreach ($contactPersons as &$contactPerson) {
  433.                 $contactPerson['content']['_uid'] = $contactPerson['uuid'];
  434.             }
  435.             $contactPersons array_values(array_filter($contactPersons, function ($contactPerson) use ($contactPersonID) {
  436.                 return $contactPerson['content']['sage_contact_person_id'] === $contactPersonID;
  437.             }));
  438.             return $contactPersons;
  439.         } catch (\Exception $e) {
  440.             return $contactPersons;
  441.         }
  442.         return $contactPersons;
  443.     }
  444.     public function getJobs()
  445.     {
  446.         return $this->sageApiService->getJobs();
  447.     }
  448.     public function getJobById($id)
  449.     {
  450.         return $this->sageApiService->getJobById($id);
  451.     }
  452.     public function isChatbubbleDisabled($lang)
  453.     {
  454.         try {
  455.             $categoryConfig $this->categoryConfigService->getByLocale($lang);
  456.             return array_key_exists('disable_chat_bubble_for_language'$categoryConfig) ? $categoryConfig['disable_chat_bubble_for_language'] . '' 'false';
  457.         } catch (\Exception $e) {
  458.             return 'false';
  459.         }
  460.     }
  461.     public function getDosingCalculatorData()
  462.     {
  463.         return $this->dosingCalculatorService->getData();
  464.     }
  465.     public function getPromotionCategoriesKeys($categories)
  466.     {
  467.         return $this->promotionService->getCategoriesKeys($categories);
  468.     }
  469.     public function getPromotionCategoryKey($categories)
  470.     {
  471.         return $this->promotionService->getCategoryKey($categories);
  472.     }
  473.     public function getPromotionCategoryTranslation($category)
  474.     {
  475.         return $this->promotionService->getCategoryTranslation($category);
  476.     }
  477.     public function getPromotions()
  478.     {
  479.         return $this->promotionService->getAll();
  480.     }
  481.     public function getPromotionsCategories()
  482.     {
  483.         return $this->promotionService->getCategories();
  484.     }
  485.     public function getWidgetByUid($uid)
  486.     {
  487.         return $this->widgetService->getByUid($uid);
  488.     }
  489.     public function getAlternatesByLocaleAndFamilyId($locale$familyId$dynamicSlug null)
  490.     {
  491.         $langsToIgnore = ['test-aus''de_austria''de_germany''cn_china_consultis''cn_china'];
  492.         $alternates = [];
  493.         try {
  494.             foreach ($this->availableLanguages as $lang) {
  495.                 if ($lang !== $locale) {
  496.                     $categoryConfig $this->categoryConfigService->getByFamilyId($lang$familyId);
  497.                     if (
  498.                         isset($categoryConfig) &&
  499.                         !$categoryConfig['hideEverywhere'] &&
  500.                         !in_array($lang$langsToIgnore)
  501.                     ) {
  502.                         if ($dynamicSlug) {
  503.                             $fullSlug $categoryConfig['seo_url'] . '/' $dynamicSlug;
  504.                             if ($this->storyblok->getStoryBySlug($fullSlug)) {
  505.                                 array_push($alternates$fullSlug);
  506.                             }
  507.                         } else {
  508.                             array_push($alternates$categoryConfig['seo_url']);
  509.                         }
  510.                     }
  511.                 }
  512.             }
  513.             return $alternates;
  514.         } catch (\Exception $e) {
  515.             return $alternates;
  516.         }
  517.     }
  518.     public function getAimsStepNumberByAnchorName($sections$anchorname)
  519.     {
  520.         $section array_filter($sections, function ($section) use ($anchorname) {
  521.             return $section['anchor_name'] === $anchorname;
  522.         });
  523.         $index array_key_first($section);
  524.         $section[$index]['index'] = $index;
  525.         return array_values($section)[0];
  526.     }
  527.     public function getAimsColorByStep($step)
  528.     {
  529.         $colorMapping = array(
  530.             'used_item' => 'dark-violet',
  531.             'cleaning' => 'congress-blue',
  532.             'disinfection' => 'lithe-blue',
  533.             'inspection' => 'bondi-blue',
  534.             'packaging' => 'jungle-green',
  535.             'sterilization' => 'apple-green',
  536.             'storage' => 'lime-yellow',
  537.             'environment' => 'cement-gray'
  538.         );
  539.         return array_key_exists($step$colorMapping) ? $colorMapping[$step] : ''//color
  540.     }
  541.     public function getAimsContentOverlayTabLinks($slide)
  542.     {
  543.         $tabs = [];
  544.         try {
  545.             $tabs $this->recursiveFind($slide'tabs');
  546.             return array_map(function ($tab) {
  547.                 return [
  548.                     'name' => $tab['name'],
  549.                 ];
  550.             }, $tabs);
  551.         } catch (\Exception $e) {
  552.             return $tabs;
  553.         }
  554.     }
  555.     private function recursiveFind(array $array$needle$searchVal null)
  556.     {
  557.         $iterator  = new \RecursiveArrayIterator($array);
  558.         $recursive = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
  559.         foreach ($recursive as $key => $value) {
  560.             if ($searchVal) {
  561.                 if ($key === $needle) {
  562.                     return $value;
  563.                 }
  564.             } else {
  565.                 if ($key === $needle) {
  566.                     return $value;
  567.                 }
  568.             }
  569.         }
  570.     }
  571.     public function getProductConfiguratorAnswersHasImage($answers)
  572.     {
  573.         $hasAnswersWithImage false;
  574.         foreach ($answers as $answer) {
  575.             if ($answer['image']['filename']) {
  576.                 $hasAnswersWithImage true;
  577.                 break;
  578.             }
  579.         }
  580.         return $hasAnswersWithImage;
  581.     }
  582.     public function getDatasourceEntries($slug)
  583.     {
  584.         $entries $this->storyblok->getDatasourceEntries($slug, [
  585.             'page' => 1,
  586.             'per_page' => 1000
  587.         ])->getBody();
  588.         return $entries['datasource_entries'];
  589.     }
  590.     public function getUserCountryCode()
  591.     {
  592.         return $this->requestStack->getCurrentRequest()->attributes->get('HTTP_CLOUDFRONT_VIEWER_COUNTRY');
  593.     }
  594.     public function getDatareporterActivationcodeUrl(): string
  595.     {
  596.         return $this->datareporterUrlActivationCode;
  597.     }
  598.     public function getDatareporterUrl(): string
  599.     {
  600.         return $this->datareporterUrl;
  601.     }
  602.     public function getNewsroomNewsWithFilter($filter$count 200)
  603.     {
  604.         return $this->newsroomService->getNewsWithFilter($filter$count);
  605.     }
  606.     public function getUserProfile()
  607.     {
  608.         return $this->userService->getProfile();
  609.     }
  610.     public function isNewsroomRefreshEnabledForLanguage($language)
  611.     {
  612.         return str_contains($this->newsroomRefreshLanguages$language);
  613.     }
  614.     public function getNewsroomArticlesByType($type)
  615.     {
  616.         return $this->newsroomService->getArticlesByType($type);
  617.     }
  618.     public function getNewsroomPathByType($type)
  619.     {
  620.         return $this->newsroomService->getPathByType($type);
  621.     }
  622.     public function getNewsroomIntervalDateAgo($date$format '%a')
  623.     {
  624.         if ($date) {
  625.             $date1 date_create(date('Y-m-d'time()));
  626.             $date2 date_create(date('Y-m-d'strtotime($date)));
  627.             $diff date_diff($date1$date2)->format($format);
  628.             return $diff;
  629.         }
  630.         return '';
  631.     }
  632.     public function getNewsroomTagTranslation($tag)
  633.     {
  634.         return $this->newsroomService->getTagTranslation($tag);
  635.     }
  636.     public function getNewsroomTags()
  637.     {
  638.         return $this->newsroomService->getTags();
  639.     }
  640.     public function getNewsroomArticlesByPath($path)
  641.     {
  642.         return $this->newsroomService->getArticlesByPath($path);
  643.     }
  644.     public function getNewsroomArticlesByFamilyId($familyId)
  645.     {
  646.         return $this->newsroomService->getArticlesByFamilyId($familyId);
  647.     }
  648.     public function getNewsroomMainCategoryByType($type)
  649.     {
  650.         return $this->newsroomService->getMainCategoryByType($type);
  651.     }
  652.     public function getNewsroomMainCategories()
  653.     {
  654.         return $this->newsroomService->getMainCategories();
  655.     }
  656.     public function getNewsroomArticles()
  657.     {
  658.         return $this->newsroomService->getArticles();
  659.     }
  660.     public function getStudentsSourcefield($lang)
  661.     {
  662.         $whitelist = array("cz_czech");
  663.         if (in_array($lang$whitelist)) {
  664.             return 'students';
  665.         } else {
  666.             return 'web';
  667.         }
  668.     }
  669.     public function getGoogleSiteVerificationContent()
  670.     {
  671.         return $this->googleSiteVerificationContent;
  672.     }
  673.     public function getCurrentEnv()
  674.     {
  675.         return $_SERVER['APP_ENV'];
  676.     }
  677.     public function loadExternalFile($path)
  678.     {
  679.         try {
  680.             $parsed_url parse_url($path);
  681.             $protocol stripos($_SERVER['SERVER_PROTOCOL'], 'https') === 'https:' 'http:';
  682.             return file_get_contents(array_key_exists('scheme'$parsed_url) ? $path $protocol $path);
  683.         } catch (\Exception $e) {
  684.             return 'ICON COULD NOT BE LOADED';
  685.         }
  686.     }
  687.     public function getAimsStepDisplayNames($steps)
  688.     {
  689.         $array_map array_map(
  690.             function ($item) {
  691.                 return $item['content']['display_name'] ? $item['content']['display_name'] : str_replace('_'' 'ucfirst($item['content']['anchor_name']));
  692.             },
  693.             $steps
  694.         );
  695.         return $array_map;
  696.     }
  697.     public function getAimsStepIndexes($steps)
  698.     {
  699.         $array_map array_map(
  700.             function ($item) {
  701.                 return $item['content']['anchor_name'];
  702.             },
  703.             $steps
  704.         );
  705.         return $array_map;
  706.     }
  707.     public function getAimsSteps($starts_with$singleStory false)
  708.     {
  709.         return $this->aimsService->getStepsSorted($starts_with$singleStory);
  710.     }
  711.     public function markdown($text)
  712.     {
  713.         if (is_string($text)) {
  714.             return \ParsedownExtraPlugin::instance()
  715.                 ->setMarkupEscaped(false)
  716.                 ->setBreaksEnabled(true)
  717.                 ->text($text);
  718.         }
  719.         return '';
  720.     }
  721.     public function getRandomNumbers($min$max$amount)
  722.     {
  723.         if ($amount <= 1) {
  724.             return random_int($min$max);
  725.         }
  726.         $arr = array();
  727.         for ($i 1$i <= $amount$i++) {
  728.             $number random_int($min$max);
  729.             if (in_array($number$arr)) {
  730.                 $i--;
  731.             } else {
  732.                 array_push($arr$number);
  733.             }
  734.         }
  735.         return $arr;
  736.     }
  737.     public function removeNbsp($content)
  738.     {
  739.         $string htmlentities($contentnull'utf-8');
  740.         $content str_replace("&nbsp;"" "$string);
  741.         $content html_entity_decode($content);
  742.         return $content;
  743.     }
  744.     public function isStaticUserLoggedIn($id)
  745.     {
  746.         return $this->userService->isStaticUserLoggedIn($id);
  747.     }
  748.     public function getSpaceID()
  749.     {
  750.         return $this->spaceId;
  751.     }
  752.     public function getMAPIToken()
  753.     {
  754.         return $this->mapiToken;
  755.     }
  756.     public function getVideoChannelUrl($categoryLang)
  757.     {
  758.         $baseUrl 'https://video.wh.com/';
  759.         $list = ['cz_czech' => 'en_global'];
  760.         if (array_key_exists($categoryLang$list)) {
  761.             return $baseUrl $list[$categoryLang];
  762.         } else {
  763.             return $baseUrl $categoryLang;
  764.         }
  765.     }
  766.     public function getTeasersByUri($uri)
  767.     {
  768.         $articles =  $this->teaserIncludeService->getTeasersByUri($uri);
  769.         return $articles;
  770.     }
  771.     public function getDomain()
  772.     {
  773.         return $this->domain;
  774.     }
  775.     public function logErrorReferrer()
  776.     {
  777.         $request $this->requestStack->getCurrentRequest();
  778.         $this->logger->error('Error Page: ' $request->headers->get('referer'));
  779.     }
  780.     public function getRefererLink()
  781.     {
  782.         $request $this->requestStack->getCurrentRequest();
  783.         return $request->headers->get('referer');
  784.     }
  785.     public function getLanguageSwitchLinks($locale$alternates$isMicrosite false)
  786.     {
  787.         $links = [];
  788.         foreach ($this->availableLanguages as $language) {
  789.             if ($language != $locale) {
  790.                 $alternatesLength count($alternates);
  791.                 $i 0;
  792.                 while (!isset($links[$language]) && $i $alternatesLength) {
  793.                     $alternate $alternates[$i];
  794.                     $alternateLang explode('/'$alternate['full_slug'])[0];
  795.                     if ($alternateLang == $language) {
  796.                         $links[$language] = $alternate['full_slug'];
  797.                         if ($isMicrosite && $_SERVER['APP_ENV'] !== "dev") {
  798.                             $links[$language] = str_replace('/microsites'''$links[$language]);
  799.                             foreach ($this->micrositeNameMap as $key => $micrositeName) {
  800.                                 $links[$language] = str_replace('/' $micrositeName''$links[$language]);
  801.                             }
  802.                         }
  803.                     }
  804.                     $i += 1;
  805.                 }
  806.                 if (!isset($links[$language])) {
  807.                     $links[$language] = $language;
  808.                 }
  809.             }
  810.         }
  811.         return $links;
  812.     }
  813.     public function microtime()
  814.     {
  815.         return round(microtime(true) * 1000);
  816.     }
  817.     public function resetArrayKeys($array)
  818.     {
  819.         return array_values($array);
  820.     }
  821.     public function getTeaserByPath($count$path$criterias)
  822.     {
  823.         return $this->announcementService->getTeaserByPath($count$path$criterias);
  824.     }
  825.     public function getNews($count$criterias)
  826.     {
  827.         return $this->announcementService->getNews($count$criterias, ['news''reports-and-studies''kurz-mal-weg']);
  828.     }
  829.     public function getBlogNews($count$criterias)
  830.     {
  831.         return $this->announcementService->getNews($count$criterias, ['kurz-mal-weg']);
  832.     }
  833.     public function getStudentNews($count$criterias)
  834.     {
  835.         return $this->announcementService->getNews($count$criterias, ['student-news''news''reports-and-studies']);
  836.     }
  837.     public function getNewsletter($count)
  838.     {
  839.         return $this->announcementService->getNewsletter($count);
  840.     }
  841.     public function getSearchHeadersForResultsPage()
  842.     {
  843.         return $this->searchService->getSearchHeadersForResultsPage();
  844.     }
  845.     public function getClosestRetailer($lat$lng$countryCode)
  846.     {
  847.         return $this->serviceStationLocatorService->getClosestRetailer($lat$lng$countryCode);
  848.     }
  849.     public function getProductNavigation($locale$familyId)
  850.     {
  851.         return $this->menuService->getProductNavigationByFamilyId($locale$familyId);
  852.     }
  853.     public function getMicrositeNavigation($category)
  854.     {
  855.         return $this->menuService->getMicrositeNavigation($category);
  856.     }
  857.     public function getNavigation($locale)
  858.     {
  859.         return $this->menuService->getNavigation($locale);
  860.     }
  861.     public function getLeftNavigation($locale$navigationSlug)
  862.     {
  863.         return $this->menuService->getLeftNavigation($locale$navigationSlug);
  864.     }
  865.     public function getCurrentLocation()
  866.     {
  867.         return $this->locationService->getCurrentLocation();
  868.     }
  869.     public function getShopUrl($locale)
  870.     {
  871.         if (!array_key_exists($locale$this->shopDomains)) {
  872.             return null;
  873.         }
  874.         $domain $this->shopDomains[$locale]['domain'];
  875.         $location strtolower($this->getCurrentLocation());
  876.         $path $this->shopDomains[$locale]['path'];
  877.         $mappedCountry array_key_exists($location$this->countryLanguageMapping) ? $this->countryLanguageMapping[$location] : null;
  878.         if ($mappedCountry && $mappedCountry !== $locale) {
  879.             $newLocation array_search($locale$this->countryLanguageMapping);
  880.             $location $newLocation $newLocation $location;
  881.         }
  882.         return $domain $location $path;
  883.     }
  884.     public function getCurrentLatitude()
  885.     {
  886.         return $this->locationService->getCurrentLatitude();
  887.     }
  888.     public function getCurrentLongitude()
  889.     {
  890.         return $this->locationService->getCurrentLongitude();
  891.     }
  892.     /**
  893.      * @param $level
  894.      * @return array
  895.      * @throws \Exception
  896.      */
  897.     public function getCategory($level)
  898.     {
  899.         return $this->categoryConfigService->getByLevel($level);
  900.     }
  901.     public function getSitemap($locale)
  902.     {
  903.         return $this->menuService->getSitemap($locale);
  904.     }
  905.     public function version($url)
  906.     {
  907.         return $this->addToUrl($url'version'$this->cacheVersion);
  908.     }
  909.     public function isEditMode()
  910.     {
  911.         return $this->storyblokHelper->isEditmode();
  912.     }
  913.     public function getCountryContactData($lang)
  914.     {
  915.         try {
  916.             $jsonString file_get_contents($this->projectDir '/public/data/contacts/' $lang '_contact.json');
  917.             $jsonString preg_replace('/[\x00-\x1F\x7F]/u'''$jsonString);
  918.             return \json_decode($jsonString);
  919.         } catch (\Exception $e) {
  920.             return \json_decode('');
  921.         }
  922.     }
  923.     public function getStories($starts_with)
  924.     {
  925.         $now date('Y-m-d H:i');
  926.         try {
  927.             $options = [
  928.                 'starts_with' => $starts_with,
  929.                 'per_page' => 500,
  930.                 'filter_query[fromDate][lt-date]' => $now,
  931.                 'filter_query[toDate][gt-date]' => $now,
  932.                 'sort_by' => 'content.fromDate:desc'
  933.             ];
  934.             $stories $this->storyblok->getStories($options)->getBody()['stories'];
  935.             return $stories;
  936.         } catch (\Exception $e) {
  937.             return [];
  938.         }
  939.     }
  940.     public function getStoryBySlug($fullSlug)
  941.     {
  942.         try {
  943.             //check if is UUID format
  944.             if (preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i'$fullSlug)) {
  945.                 $this->storyblok->getStoryByUuid($fullSlug);
  946.             } else {
  947.                 $this->storyblok->getStoryBySlug($fullSlug);
  948.             }
  949.             $data $this->storyblok->getBody();
  950.             return $data['story'];
  951.         } catch (\Exception $e) {
  952.             return [];
  953.         }
  954.     }
  955.     public function getDocumentObject($documentID$documentTypeDocfinder$documentTypeManual)
  956.     {
  957.         return $this->documentService->createDocObject($documentID$documentTypeDocfinder$documentTypeManual);
  958.     }
  959.     public function documentInfo($documentInfo$documentTypeId$countryId$langId "")
  960.     {
  961.         return $this->documentService->get($documentInfo$documentTypeId$countryId$langId);
  962.     }
  963.     public function getCanonical()
  964.     {
  965.         $canonical $this->getDomain() . $this->requestStack->getCurrentRequest()->getPathInfo();
  966.         return $canonical;
  967.     }
  968.     public function getFontCacheKey()
  969.     {
  970.         return $this->fontCacheKey;
  971.     }
  972.     public function getGoogleAnalyticsId()
  973.     {
  974.         return $this->googleAnalyticsKey;
  975.     }
  976.     public function systemConf($confProperty)
  977.     {
  978.         return getenv("SYSTEM_CONF_" $confProperty);
  979.     }
  980.     public function getBackendPath()
  981.     {
  982.         return getenv("BACKEND_URL");
  983.     }
  984.     /**
  985.      * @return string
  986.      * @throws \Exception
  987.      */
  988.     public function uuid()
  989.     {
  990.         $data random_bytes(16);
  991.         $data[6] = chr(ord($data[6]) & 0x0f 0x40);
  992.         $data[8] = chr(ord($data[8]) & 0x3f 0x80);
  993.         return vsprintf('%s%s-%s-%s-%s-%s%s%s'str_split(bin2hex($data), 4));
  994.     }
  995.     /**
  996.      * @return string
  997.      * @throws \Exception
  998.      */
  999.     function uniqid()
  1000.     {
  1001.         return uniqid();
  1002.     }
  1003.     public function hasImageCorrectSize($image$size$compareOnlyWidth false)
  1004.     {
  1005.         if (strpos($image'a.storyblok') !== false) {
  1006.             $url_data array_filter(explode("/"$image), 'strlen');
  1007.             $dimension $url_data[5];
  1008.             if ($compareOnlyWidth) {
  1009.                 $dimensionWidth explode("x"$dimension)[0];
  1010.                 $sizeWidth explode("x"$size)[0];
  1011.                 return $dimensionWidth !== $sizeWidth;
  1012.             }
  1013.             return $dimension !== $size;
  1014.         }
  1015.         return false;
  1016.     }
  1017.     public function image($image$isNoImage false$size '')
  1018.     {
  1019.         $optimizedPath '';
  1020.         if ($size !== '') {
  1021.             $optimizedPath '/m/' $size;
  1022.         }
  1023.         // TODO to be removed in future:
  1024.         if ($isNoImage) {
  1025.             return $image;
  1026.         } else if (strpos($image'a.storyblok') === false && strpos($image'-micropage') === false) {
  1027.             $image 'https://www.wh.com' $image;
  1028.         } else if (strpos($image'a.storyblok') !== false) {
  1029.             $image trim($image) . $optimizedPath '?t=' time();
  1030.         } else {
  1031.             $image trim($image) . '?t=' time();
  1032.         }
  1033.         return $image;
  1034.     }
  1035.     public function url($url)
  1036.     {
  1037.         // TODO to be removed in future:
  1038.         if (strpos($url'a.storyblok') === false) {
  1039.             $url 'https://www.wh.com' $url;
  1040.         }
  1041.         return $url;
  1042.     }
  1043.     public function sbUrl($link)
  1044.     {
  1045.         if ($link['linktype'] == "story") {
  1046.             $uuid $link['id'];
  1047.             if (isset($uuid) && $this->linkService->hasLink($uuid)) {
  1048.                 return '/' $this->linkService->getLinkByUUID($uuid)['slug'];
  1049.             }
  1050.         }
  1051.         return isset($link['url']) ? $link['url'] : $link;
  1052.     }
  1053.     public function sbUrlByUuid($uuid)
  1054.     {
  1055.         if (isset($uuid) && $this->linkService->hasLink($uuid)) {
  1056.             return '/' $this->linkService->getLinkByUUID($uuid)['slug'];
  1057.         }
  1058.     }
  1059.     public function sbUrlById($id)
  1060.     {
  1061.         $result $this->linkService->getLinkById($id);
  1062.         if ($result) {
  1063.             return $result['slug'];
  1064.         } else {
  1065.             $this->logger->warning("Wasn't able to find link for id: " $id);
  1066.             return $id;
  1067.         }
  1068.     }
  1069.     public function getStoryById($id)
  1070.     {
  1071.         try {
  1072.             $fullSlug $this->sbUrlById($id);
  1073.             $this->storyblok->getStoryBySlug($fullSlug);
  1074.             return $this->storyblok->getBody();
  1075.         } catch (\Exception $e) {
  1076.             $this->logger->error($e);
  1077.             return null;
  1078.         }
  1079.     }
  1080.     public function getStoryByUuid($uuid)
  1081.     {
  1082.         try {
  1083.             $fullSlug $this->sbUrlByUuid($uuid);
  1084.             $this->storyblok->getStoryBySlug($fullSlug);
  1085.             return $this->storyblok->getBody();
  1086.         } catch (\Exception $e) {
  1087.             $this->logger->error($e);
  1088.             return null;
  1089.         }
  1090.     }
  1091.     public function getFamilyPart($familyId$index)
  1092.     {
  1093.         $familyParts explode('/'$familyId);
  1094.         if ($index == -1) {
  1095.             # breadcrumb
  1096.             $result $familyId;
  1097.         } else if ($index >= count($familyParts)) {
  1098.             $result "";
  1099.         } else {
  1100.             $result $familyParts[$index];
  1101.         }
  1102.         return $result;
  1103.     }
  1104.     public function getSkus($storyContent)
  1105.     {
  1106.         $fieldName "productBlockPRName";
  1107.         $result = [];
  1108.         foreach (array_keys($storyContent) as $key => $value) {
  1109.             if (strpos($key$fieldName) > -1) {
  1110.                 array_push($result$value);
  1111.             } else if (is_array($value)) {
  1112.                 foreach ($value as $child) {
  1113.                     $result array_merge($result$this->getSkus($child));
  1114.                 }
  1115.             }
  1116.         }
  1117.         return $result;
  1118.     }
  1119.     public function includeFile($path)
  1120.     {
  1121.         try {
  1122.             $fullPath $this->projectDir '/public/' $path;
  1123.             return file_get_contents($fullPath);
  1124.         } catch (\Exception $e) {
  1125.             $this->logger->error($e);
  1126.             throw new \Exception("Was not able to include file.");
  1127.         }
  1128.     }
  1129.     public function familyUrl($lang$familyId)
  1130.     {
  1131.         $categoryConfig $this->categoryConfigService->getByFamilyId($lang$familyId);
  1132.         if (isset($categoryConfig)) {
  1133.             return $categoryConfig['seo_url'];
  1134.         }
  1135.         return "#";
  1136.     }
  1137.     public function rindex($haystack$needle$offset 0)
  1138.     {
  1139.         return strrpos($haystack$needle$offset);
  1140.     }
  1141.     /**
  1142.      * @param $key
  1143.      * @return string
  1144.      * @throws \Psr\Cache\InvalidArgumentException
  1145.      */
  1146.     public function label($key)
  1147.     {
  1148.         return $this->labelService->getLabel($key);
  1149.     }
  1150.     public function getNewsletterOgInfoById($nlid)
  1151.     {
  1152.         $ogData = new \stdClass();
  1153.         $ogData->hasData false;
  1154.         if ($nlid != null) {
  1155.             try {
  1156.                 $request_url $_SERVER['PHP_SELF'];
  1157.                 $fullSlug $request_url '/' $nlid;
  1158.                 $this->storyblok->getStoryBySlug($fullSlug);
  1159.                 $data $this->storyblok->getBody();
  1160.                 $ogData->title $data['story']['content']['nl_teaserheadline'];
  1161.                 $ogData->url $_SERVER['REQUEST_URI'] . '?nlid=' $nlid;
  1162.                 $ogData->image $data['story']['content']['nl_teaserimage'];
  1163.                 $ogData->description $data['story']['content']['nl_teasertext'];
  1164.                 $ogData->hasData true;
  1165.             } catch (\Exception $e) {
  1166.                 return $ogData;
  1167.             }
  1168.         }
  1169.         return $ogData;
  1170.     }
  1171.     public function generateBreadcrumb()
  1172.     {
  1173.         $url $this->requestStack->getCurrentRequest()->getPathInfo();
  1174.         $urlwithoutSlash join('/'array_slice(explode('/'$url), 1));
  1175.         try {
  1176.             $slug $this->categoryConfigService->getSlugByUrl($urlwithoutSlash);
  1177.             $breadcrumbs $this->menuService->getBreadcrumbs($slug);
  1178.             $breadcrumbs array_filter($breadcrumbs, function ($item) {
  1179.                 return !str_contains($item['url'], 'archive');
  1180.             });
  1181.             return $breadcrumbs;
  1182.         } catch (\Exception $exception) {
  1183.             $this->logger->warning($exception->getMessage());
  1184.             return [];
  1185.         }
  1186.     }
  1187.     public function getVideoTutorialsByProductId($productId$langId)
  1188.     {
  1189.         return $this->videoTutorialService->getByProductId($productId$langId);
  1190.     }
  1191.     public function getAccessoriesByProductId($productId$langId)
  1192.     {
  1193.         return $this->accessoryService->getAccessoriesByProductId($productId$langId);
  1194.     }
  1195.     public function getNextEvent($langId$filterCountry)
  1196.     {
  1197.         return $this->eventService->getNextEvent($langId$filterCountry);
  1198.     }
  1199.     public function getFAQsByProductId($productId$langId$faqPath)
  1200.     {
  1201.         return $this->faqService->getFAQsByProductId($productId$langId$faqPath);
  1202.     }
  1203.     public function getFAQsByApplicationArea($langId$applicationAreaId "")
  1204.     {
  1205.         return $this->faqService->getFAQsByApplicationArea($langId$applicationAreaId);
  1206.     }
  1207.     public function overviewData(string $pathstring $contentTypeint $page 1int $limit 10string $sortBy null)
  1208.     {
  1209.         return $this->overviewService->getOverviewData($path$contentType$page$limit$sortBy);
  1210.     }
  1211.     public function getScienceCenterByProductId($productId$langId): array
  1212.     {
  1213.         return $this->scienceCenterService->getByProductId($productId$langId);
  1214.     }
  1215.     // TODO: When there is time, move these extensions into the Symfony "user" object
  1216.     public function isUserLoggedIn()
  1217.     {
  1218.         return $this->userService->isLoggedIn();
  1219.     }
  1220.     public function activateUser($userId)
  1221.     {
  1222.         return $this->userService->activate($userId);
  1223.     }
  1224.     public function isStudentUser()
  1225.     {
  1226.         return $this->userService->isStudent();
  1227.     }
  1228.     // TODO: When there is time, move these extensions into the Symfony "user" object
  1229.     public function userFirstname()
  1230.     {
  1231.         return $this->userService->getFirstname();
  1232.     }
  1233.     public function getToken()
  1234.     {
  1235.         return $this->userService->getToken();
  1236.     }
  1237.     private function addToUrl($url$key$value null)
  1238.     {
  1239.         $query parse_url($urlPHP_URL_QUERY);
  1240.         if ($query) {
  1241.             parse_str($query$queryParams);
  1242.             $queryParams[$key] = $value;
  1243.             $url str_replace("?$query"'?' http_build_query($queryParams), $url);
  1244.         } else {
  1245.             $url .= '?' urlencode($key) . '=' urlencode($value);
  1246.         }
  1247.         return $url;
  1248.     }
  1249.     public function addTeaserName(string $teaserName)
  1250.     {
  1251.         $request $this->requestStack->getCurrentRequest();
  1252.         $teaserNames $request->attributes->get('teaserNames');
  1253.         $teaserNames[] = $teaserName;
  1254.         $request->attributes->set('teaserNames'$teaserNames);
  1255.     }
  1256.     public function getAllTeaserNamesFormatted()
  1257.     {
  1258.         $names $this->requestStack->getCurrentRequest()->attributes->get('teaserNames');
  1259.         return $this->formatArrayForAnalytics($names $names : []);
  1260.     }
  1261.     public function addNewsName(string $newsName)
  1262.     {
  1263.         $request $this->requestStack->getCurrentRequest();
  1264.         $newsNames $request->attributes->get('newsNames');
  1265.         $newsNames[] = $newsName;
  1266.         $request->attributes->set('newsNames'$newsNames);
  1267.     }
  1268.     public function getAllNewsNamesFormatted()
  1269.     {
  1270.         $names $this->requestStack->getCurrentRequest()->attributes->get('newsNames');
  1271.         return $this->formatArrayForAnalytics($names $names : []);
  1272.     }
  1273.     private function formatArrayForAnalytics(array $array)
  1274.     {
  1275.         $arrayLength count($array);
  1276.         $arrayString '';
  1277.         for ($i 0$i $arrayLength$i += 1) {
  1278.             $arrayString .= strtolower($array[$i]);
  1279.             if ($i < ($arrayLength 1)) {
  1280.                 $arrayString .= '; ';
  1281.             }
  1282.         }
  1283.         return $arrayString;
  1284.     }
  1285.     public function getRecaptchaSitekey(): string
  1286.     {
  1287.         return $this->recaptchaConfig['sitekey'];
  1288.     }
  1289.     public function formatDateByLocale($locale$date$format)
  1290.     {
  1291.         switch ($locale) {
  1292.             case 'de_global':
  1293.                 setlocale(LC_TIME'de_DE');
  1294.                 break;
  1295.             case 'en_global':
  1296.                 setlocale(LC_TIME'en_GB');
  1297.                 break;
  1298.             case 'es_global':
  1299.                 setlocale(LC_TIME'es_ES');
  1300.                 break;
  1301.             case 'es_iberica':
  1302.                 setlocale(LC_TIME'es_ES');
  1303.                 break;
  1304.             case 'en_na':
  1305.                 setlocale(LC_TIME'en_CA');
  1306.                 break;
  1307.             case 'en_uk':
  1308.                 setlocale(LC_TIME'en_GB');
  1309.                 break;
  1310.             case 'en_australia':
  1311.                 setlocale(LC_TIME'en_AU');
  1312.                 break;
  1313.             case 'pl_poland':
  1314.                 setlocale(LC_TIME'pl_PL');
  1315.                 break;
  1316.             case 'bg_bulgaria':
  1317.                 setlocale(LC_TIME'bg_BG');
  1318.                 break;
  1319.             case 'ru_cis':
  1320.                 setlocale(LC_TIME'ru_RU');
  1321.                 break;
  1322.             case 'cn_china':
  1323.                 setlocale(LC_TIME'cn_CN');
  1324.                 break;
  1325.             case 'de_germany':
  1326.                 setlocale(LC_TIME'de_DE');
  1327.                 break;
  1328.             case 'de_austria':
  1329.                 setlocale(LC_TIME'de_DE');
  1330.                 break;
  1331.             case 'it_italy':
  1332.                 setlocale(LC_TIME'it_IT');
  1333.                 break;
  1334.             case 'fr_france':
  1335.                 setlocale(LC_TIME'fr_FR');
  1336.                 break;
  1337.             case 'dk_nordic':
  1338.                 setlocale(LC_TIME'dk_DK');
  1339.                 break;
  1340.             case 'se_nordic':
  1341.                 setlocale(LC_TIME'se_SE');
  1342.                 break;
  1343.             case 'tk_turkey':
  1344.                 setlocale(LC_TIME'tr_TR');
  1345.                 break;
  1346.             case 'ro_romania':
  1347.                 setlocale(LC_TIME'ro_RO');
  1348.                 break;
  1349.             case 'pt_brasil':
  1350.                 setlocale(LC_TIME'pt_BR');
  1351.                 break;
  1352.             default:
  1353.                 setlocale(LC_TIME'en_GB');
  1354.                 break;
  1355.         }
  1356.         return strftime($formatstrtotime($date));
  1357.     }
  1358.     public function getAboriginalCountryDatasources()
  1359.     {
  1360.         $locale $this->requestStack->getCurrentRequest()->getLocale();
  1361.         $aboriginalCountry $this->storyblok->getDatasourceEntries('aboriginal-country', [
  1362.             'page' => 1,
  1363.             'per_page' => 1000,
  1364.             'dimension' => $locale
  1365.         ])->getBody();
  1366.         return $aboriginalCountry['datasource_entries'];
  1367.     }
  1368. }