Next major version 2 with PHP 8.1, Symfony 6, Tabler UI, 2FA ... (#2902)

This commit is contained in:
Kevin Papst
2022-12-31 21:19:55 +01:00
committed by GitHub
parent 95e06746bd
commit 90a0fd8a22
2164 changed files with 83700 additions and 86426 deletions

View File

@@ -9,38 +9,24 @@
namespace App\EventSubscriber;
use App\Configuration\LocaleService;
use App\Entity\User;
use App\Entity\UserPreference;
use App\Form\Type\SkinType;
use KevinPapst\AdminLTEBundle\Helper\ContextHelper;
use KevinPapst\TablerBundle\Helper\ContextHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\KernelEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
/**
* Allows dynamic injection of theme related options.
* Prepare all theme settings for user and context.
*/
final class ThemeOptionsSubscriber implements EventSubscriberInterface
{
/**
* @var TokenStorageInterface
*/
private $storage;
/**
* @var ContextHelper
*/
private $helper;
public function __construct(TokenStorageInterface $storage, ContextHelper $helper)
public function __construct(private TokenStorageInterface $storage, private ContextHelper $helper, private LocaleService $localeService)
{
$this->storage = $storage;
$this->helper = $helper;
}
/**
* @return array
*/
public static function getSubscribedEvents(): array
{
return [
@@ -51,10 +37,14 @@ final class ThemeOptionsSubscriber implements EventSubscriberInterface
public function setThemeOptions(KernelEvent $event): void
{
// Ignore sub-requests
if (!$event->isMasterRequest()) {
if (!$event->isMainRequest()) {
return;
}
if ($this->localeService->isRightToLeft(\Locale::getDefault())) {
$this->helper->setIsRightToLeft(true);
}
// ignore events like the toolbar where we do not have a token
if (null === $this->storage->getToken()) {
return;
@@ -66,30 +56,18 @@ final class ThemeOptionsSubscriber implements EventSubscriberInterface
return;
}
/** @var UserPreference $ref */
foreach ($user->getPreferences() as $ref) {
$name = $ref->getName();
switch ($name) {
case UserPreference::SKIN:
if (!empty($ref->getValue()) && \in_array($ref->getValue(), SkinType::THEMES)) {
$this->helper->setOption('skin', 'skin-' . $ref->getValue());
}
break;
$skin = $user->getPreferenceValue(UserPreference::SKIN);
if ($skin === 'dark') {
$this->helper->setIsDarkMode(true);
}
case 'theme.layout':
if ($ref->getValue() === 'boxed') {
$this->helper->setOption('boxed_layout', true);
$this->helper->setOption('fixed_layout', false);
} else {
$this->helper->setOption('boxed_layout', false);
$this->helper->setOption('fixed_layout', true);
}
break;
case 'theme.collapsed_sidebar':
$this->helper->setOption('collapsed_sidebar', $ref->getValue());
break;
}
// do not allow boxed layout, header is not compatible and other functions need the full size as well
$this->helper->setIsBoxedLayout(false);
$this->helper->setIsCondensedUserMenu(false);
$this->helper->setIsCondensedNavbar(false);
$this->helper->setIsNavbarOverlapping(false);
if (!$this->helper->isDarkMode()) {
$this->helper->setIsNavbarDark(true);
}
}
}