src/ApplicationBundle/Modules/LeadGen/Twig/BrandingExtension.php line 46

Open in your IDE?
  1. <?php
  2. namespace ApplicationBundle\Modules\LeadGen\Twig;
  3. use ApplicationBundle\Modules\Authentication\Constants\UserConstants;
  4. use ApplicationBundle\Modules\CentralControl\Support\PlatformFlagConfig;
  5. use ApplicationBundle\Modules\LeadGen\Helper\BrandingHelper;
  6. use Twig\Extension\AbstractExtension;
  7. use Twig\TwigFunction;
  8. /**
  9.  * GR1 — thin twig surface over BrandingHelper so the shared footer partial works on EVERY kind
  10.  * of template (public tokened pages get app_id as a var; logged-in prints fall back to the
  11.  * session; templates with neither still render — just without the t param).
  12.  *
  13.  *   hb_branding_enabled()          — tenant kill switch (acc_setting branding_removal_enabled)
  14.  *   hb_backlink(surface, appId)    — https://ourhoneybee.eu/?ref=<surface>&t=<tenantHash>
  15.  *   hb_tagline()                   — the one approved copy line
  16.  */
  17. class BrandingExtension extends AbstractExtension
  18. {
  19.     private $em;
  20.     private $container;
  21.     public function __construct($em$container null)
  22.     {
  23.         $this->em $em;
  24.         $this->container $container;
  25.     }
  26.     public function getFunctions()
  27.     {
  28.         return [
  29.             new TwigFunction('hb_branding_enabled', [$this'brandingEnabled']),
  30.             new TwigFunction('hb_backlink', [$this'backlink']),
  31.             new TwigFunction('hb_tagline', [$this'tagline']),
  32.         ];
  33.     }
  34.     /**
  35.      * CC7 — central DESIRED state wins when present; otherwise the local acc_setting reader,
  36.      * UNCHANGED (fails OPEN to showing branding). appId comes from the template (public tokened
  37.      * pages pass it) or the logged-in session. A central hiccup ⇒ centralDesiredRaw() is null ⇒
  38.      * local path ⇒ branding shows: the flag can still only ever REMOVE a footer, never break a page.
  39.      */
  40.     public function brandingEnabled($appId 0)
  41.     {
  42.         $appId = (int) $appId;
  43.         if ($appId <= 0) {
  44.             $appId $this->sessionAppId();
  45.         }
  46.         if ($this->container !== null && $appId 0) {
  47.             $desired PlatformFlagConfig::centralDesiredRaw($this->container$appId'branding_removal_enabled');
  48.             if ($desired !== null) {
  49.                 return !BrandingHelper::brandingRemoved($desired);
  50.             }
  51.         }
  52.         return BrandingHelper::brandingEnabled($this->em);
  53.     }
  54.     private function sessionAppId()
  55.     {
  56.         try {
  57.             if ($this->container !== null && $this->container->has('session')) {
  58.                 $session $this->container->get('session');
  59.                 return (int) $session->get(UserConstants::USER_APP_ID0);
  60.             }
  61.         } catch (\Throwable $e) {
  62.             // no session (CLI / sessionless) — fall back to local read
  63.         }
  64.         return 0;
  65.     }
  66.     public function backlink($surface$appId 0)
  67.     {
  68.         return BrandingHelper::backlink($surface$appId);
  69.     }
  70.     public function tagline()
  71.     {
  72.         return BrandingHelper::TAGLINE;
  73.     }
  74. }