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
16 class DetectActiveTheme
implements DeviceDetectionInterface
18 protected $securityContext;
19 protected $defaultTheme;
22 * @param SecurityContextInterface $securityContext Needed to retrieve the current user
23 * @param string $defaultTheme Default theme when user isn't logged in
25 public function __construct(SecurityContextInterface
$securityContext, $defaultTheme)
27 $this->securityContext
= $securityContext;
28 $this->defaultTheme
= $defaultTheme;
31 public function setUserAgent($userAgent)
36 * This should return the active theme for the logged in user.
40 * - user without a config (shouldn't happen ..)
44 public function getType()
46 $user = $this->securityContext
->getToken()->getUser();
48 if (!$user instanceof User
) {
49 return $this->defaultTheme
;
52 $config = $user->getConfig();
55 return $this->defaultTheme
;
58 return $config->getTheme();