forked from wallabag/wallabag
Remove LiipThemeBundle
As baggy theme was removed and material is the only remaining theme, we don't need a theme switched anymore. So: - move all `*.twig` files from the material theme folder to the root - remove useless translations
This commit is contained in:
@ -1,72 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace Wallabag\CoreBundle\Helper;
|
||||
|
||||
use Liip\ThemeBundle\Helper\DeviceDetectionInterface;
|
||||
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
|
||||
use Wallabag\UserBundle\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 return the default theme
|
||||
*/
|
||||
class DetectActiveTheme implements DeviceDetectionInterface
|
||||
{
|
||||
protected $tokenStorage;
|
||||
protected $defaultTheme;
|
||||
protected $themes;
|
||||
|
||||
/**
|
||||
* @param TokenStorageInterface $tokenStorage Needed to retrieve the current user
|
||||
* @param string $defaultTheme Default theme when user isn't logged in
|
||||
* @param array $themes Themes come from the LiipThemeBundle (liip_theme.themes)
|
||||
*/
|
||||
public function __construct(TokenStorageInterface $tokenStorage, $defaultTheme, $themes)
|
||||
{
|
||||
$this->tokenStorage = $tokenStorage;
|
||||
$this->defaultTheme = $defaultTheme;
|
||||
$this->themes = $themes;
|
||||
}
|
||||
|
||||
public function setUserAgent($userAgent)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* This should return the active theme for the logged in user.
|
||||
*
|
||||
* Default theme for:
|
||||
* - anonymous user
|
||||
* - user without a config (shouldn't happen ..)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType()
|
||||
{
|
||||
$token = $this->tokenStorage->getToken();
|
||||
|
||||
if (null === $token) {
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
$user = $token->getUser();
|
||||
|
||||
if (!$user instanceof User) {
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
$config = $user->getConfig();
|
||||
|
||||
if (!$config) {
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
if (!\in_array($config->getTheme(), $this->themes, true)) {
|
||||
return $this->defaultTheme;
|
||||
}
|
||||
|
||||
return $config->getTheme();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user