3 namespace Wallabag\CoreBundle\Helper
;
5 use Liip\ThemeBundle\Helper\DeviceDetectionInterface
;
6 use Symfony\Component\Security\Core\SecurityContextInterface
;
7 use Wallabag\CoreBundle\Entity\User
;
10 * This class intend to detect the active theme for the logged in user.
11 * It will retrieve the configured theme of the user.
13 * If no user where logged in, it will returne the default theme
15 class DetectActiveTheme
implements DeviceDetectionInterface
17 protected $securityContext;
18 protected $defaultTheme;
21 * @param SecurityContextInterface $securityContext Needed to retrieve the current user
22 * @param string $defaultTheme Default theme when user isn't logged in
24 public function __construct(SecurityContextInterface
$securityContext, $defaultTheme)
26 $this->securityContext
= $securityContext;
27 $this->defaultTheme
= $defaultTheme;
30 public function setUserAgent($userAgent)
35 * This should return the active theme for the logged in user.
39 * - user without a config (shouldn't happen ..)
43 public function getType()
45 $user = $this->securityContext
->getToken()->getUser();
47 if (!$user instanceof User
) {
48 return $this->defaultTheme
;
51 $config = $user->getConfig();
54 return $this->defaultTheme
;
57 return $config->getTheme();