src/Aviatur/GeneralBundle/Twig/TailwindConfig.php line 17

Open in your IDE?
  1. <?php
  2. namespace Aviatur\GeneralBundle\Twig;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  5. use Twig\Extension\AbstractExtension;
  6. use Twig\Extension\GlobalsInterface;
  7. use Aviatur\GeneralBundle\Entity\ConfigAgencyStyles;
  8. class TailwindConfig extends AbstractExtension implements GlobalsInterface
  9. {
  10.     private array $tailwindConfig = [];
  11.     public function __construct(EntityManagerInterface $emSessionInterface $session)
  12.     {
  13.         $agencyId $session->has('agencyId') ? $session->get('agencyId') : null;
  14.         $configRepo $em->getRepository(ConfigAgencyStyles::class);
  15.         
  16.         // Try to find specific agency config
  17.         $configEntity $configRepo->findOneBy(['agency' => $agencyId]);
  18.         // If specific config not found and we weren't already looking for the default (agencyId=null), try the default
  19.         if (!$configEntity && $agencyId !== null) {
  20.             $configEntity $configRepo->findOneBy(['agency' => null]);
  21.         }
  22.        
  23.         if ($configEntity) {
  24.             $this->tailwindConfig $configEntity->getConfig();
  25.         } else {
  26.             // Default config (if no agency or no config in DB)
  27.             $this->tailwindConfig = [
  28.                 'theme' => [
  29.                     'extend' => [
  30.                         'screens' => [
  31.                             'xs'    => ['max' => '575px'],
  32.                             's'     => ['min' => '576px''max' => '767px'],
  33.                             'm'     => ['min' => '768px''max' => '992px'],
  34.                             'l'     => ['min' => '993px'],
  35.                             'phone' => ['min' => '320px'],
  36.                             'tablet'=> ['min' => '721px'],
  37.                             'desk'  => ['min' => '951px'],
  38.                             'wide'  => ['min' => '1750px'],
  39.                         ],
  40.                         'colors' => [
  41.                             'primaryEmphasis' => [
  42.                                 400 => '#4D95EB',
  43.                                 300 => '#7AB5F5',
  44.                                 200 => '#A3CEFC',
  45.                                 100 => '#C6E2FF',
  46.                                 50  => '#E3F1FF',
  47.                                 25  => '#F0F7FF',
  48.                             ],
  49.                             'secondaryStrong' => [
  50.                                 900 => '#072E50',
  51.                                 800 => '#09325F',
  52.                                 700 => '#003D78',
  53.                                 600 => '#004C98',
  54.                             ],
  55.                             'grayScales' => [
  56.                                 900 => '#3A3A3A',
  57.                                 800 => '#5A5A5A',
  58.                                 700 => '#727272',
  59.                                 600 => '#8B8B8B',
  60.                                 500 => '#B1B1B1',
  61.                                 400 => '#D1D1D1',
  62.                                 300 => '#D9D9D9',
  63.                                 200 => '#EBEBEB',
  64.                                 100 => '#F0F0F0',
  65.                                 50  => '#FCFCFC',
  66.                             ],
  67.                             'success' => [
  68.                                 900 => '#045044',
  69.                                 800 => '#036251',
  70.                                 700 => '#007C66',
  71.                                 600 => '#008F72',
  72.                                 400 => '#2FDBAC',
  73.                                 300 => '#6AEBC6',
  74.                                 200 => '#A4F6D9',
  75.                                 100 => '#D0FBEA',
  76.                                 50  => '#EBFEF7',
  77.                             ],
  78.                             'warning' => [
  79.                                 900 => '#783716',
  80.                                 800 => '#954117',
  81.                                 700 => '#BC5312',
  82.                                 500 => '#F28C28',
  83.                                 400 => '#F5A242',
  84.                                 300 => '#F8C579',
  85.                                 200 => '#FBDEAD',
  86.                                 100 => '#FEF0D6',
  87.                                 50  => '#FEF8EE',
  88.                             ],
  89.                             'error' => [
  90.                                 900 => '#7D1F1F',
  91.                                 800 => '#971D1D',
  92.                                 600 => '#D92929',
  93.                                 500 => '#EC4747',
  94.                                 400 => '#F67373',
  95.                                 300 => '#FAA7A7',
  96.                                 200 => '#FDCBCB',
  97.                                 100 => '#FEE2E2',
  98.                                 50  => '#FEF2F2',
  99.                             ],
  100.                             'additionalDarkMode' => [
  101.                                 0   => '#F5F7F9',
  102.                                 900 => '#0E1A23',
  103.                                 950 => '#0D141A',
  104.                             ],
  105.                             'fundamentals' => [
  106.                                 'white' => '#FFFFFF',
  107.                                 'black' => '#000000',
  108.                             ],
  109.                             'mainWarning'   => '#E36C13',
  110.                             'mainError'     => '#AC1D1D',
  111.                             'textParagraph' => '#2F2F2F',
  112.                             'primary'       => '#005CB9',
  113.                             'secondary'     => '#042A44',
  114.                             'action'        => '#0ABF96',
  115.                         ],
  116.                     ]
  117.                 ],
  118.                 'plugins' => []
  119.             ];
  120.         }
  121.     }
  122.     public function getGlobals(): array
  123.     {
  124.         return [
  125.             'tailwind_config' => $this->tailwindConfig
  126.         ];
  127.     }
  128. }