forked from wallabag/wallabag
Cleanup & simplify theme
This commit is contained in:
@ -6,13 +6,26 @@ use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use Wallabag\CoreBundle\Entity\User;
|
||||
|
||||
/**
|
||||
* This class intend to detect the active theme for the logged in user.
|
||||
* It will retrieve the configured theme of the user.
|
||||
*
|
||||
* If no user where logged in, it will returne the default theme
|
||||
*/
|
||||
|
||||
class DetectActiveTheme implements DeviceDetectionInterface
|
||||
{
|
||||
protected $securityContext;
|
||||
protected $defaultTheme;
|
||||
|
||||
public function __construct(SecurityContextInterface $securityContext)
|
||||
/**
|
||||
* @param SecurityContextInterface $securityContext Needed to retrieve the current user
|
||||
* @param string $defaultTheme Default theme when user isn't logged in
|
||||
*/
|
||||
public function __construct(SecurityContextInterface $securityContext, $defaultTheme)
|
||||
{
|
||||
$this->securityContext = $securityContext;
|
||||
$this->defaultTheme = $defaultTheme;
|
||||
}
|
||||
|
||||
public function setUserAgent($userAgent)
|
||||
@ -21,9 +34,10 @@ class DetectActiveTheme implements DeviceDetectionInterface
|
||||
|
||||
/**
|
||||
* This should return the active theme for the logged in user.
|
||||
* No active theme for:
|
||||
*
|
||||
* Default theme for:
|
||||
* - anonymous user
|
||||
* - user without a config (shouldn't happen..)
|
||||
* - user without a config (shouldn't happen ..)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@ -31,15 +45,14 @@ class DetectActiveTheme implements DeviceDetectionInterface
|
||||
{
|
||||
$user = $this->securityContext->getToken()->getUser();
|
||||
|
||||
// anon user don't deserve a theme
|
||||
if (!$user instanceof User) {
|
||||
return false;
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
$config = $user->getConfig();
|
||||
|
||||
if (!$config) {
|
||||
return false;
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
return $config->getTheme();
|
||||
|
||||
Reference in New Issue
Block a user