src/Controller/ConfigController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Algolia\AlgoliaSearch\SearchClient;
  4. use App\Form\Model\Settings;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Contracts\Translation\TranslatorInterface;
  9. #[Route('/config')]
  10. class ConfigController extends AbstractController
  11. {
  12.     public function __construct(protected TranslatorInterface $translator)
  13.     {
  14.     }
  15.     #[Route(path'/javascript-settings.js'name'front_config_javascriptSettings')]
  16.     public function javascriptSettings(): Response
  17.     {
  18.         /*$securedApiKey = SearchClient::generateSecuredApiKey(
  19.               Settings::get('algoliaFrontEndApiKey'),
  20.               [
  21.                   'filters'              => '(locale:' . $request->getLocale() . ') AND (type:page OR type:case-study OR type:home OR type:team-member) AND status:published AND visibility:public AND visible:true',
  22.                   'attributesToRetrieve' => [
  23.                       'globalDescription',
  24.                       'globalTitle',
  25.                       'path',
  26.                       'status',
  27.                       'title',
  28.                       'description',
  29.                       'locale'
  30.                   ],
  31.               ]
  32.           );*/
  33.         $tradList     = [];
  34.         $translations = [];
  35.         foreach ($tradList as $trad) {
  36.             $translations[$trad] = $this->translator->trans($trad);
  37.         }
  38.         $response = new Response($this->renderView('front/config/javascript-settings.js.twig', [
  39.             'trads' => $translations,
  40. //            'algoliaApiKey' => $securedApiKey,
  41.         ]));
  42.         $response->headers->set('Content-Type''text/javascript');
  43.         return $response;
  44.     }
  45. }