3 namespace Wallabag\CoreBundle\Helper
;
5 use Liip\ThemeBundle\Helper\DeviceDetectionInterface
;
6 use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface
;
7 use Wallabag\UserBundle\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 $tokenStorage;
18 protected $defaultTheme;
21 * @param TokenStorageInterface $tokenStorage Needed to retrieve the current user
22 * @param string $defaultTheme Default theme when user isn't logged in
24 public function __construct(TokenStorageInterface
$tokenStorage, $defaultTheme)
26 $this->tokenStorage
= $tokenStorage;
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 $token = $this->tokenStorage
->getToken();
47 if (null === $token) {
48 return $this->defaultTheme
;
51 $user = $token->getUser();
53 if (!$user instanceof User
) {
54 return $this->defaultTheme
;
57 $config = $user->getConfig();
60 return $this->defaultTheme
;
63 return $config->getTheme();