Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI across Symfony versions #359

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions config/listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
service(ConfigLoader::class),
service('contao.intl.locales'),
service(TranslatorInterface::class),
service('security.helper'),
service('request_stack'),
])
;

Expand All @@ -65,7 +65,7 @@
service(ConfigLoader::class),
service('contao.framework'),
service('database_connection'),
service('security.helper'),
service('request_stack'),
service('twig'),
service('contao.intl.locales'),
])
Expand Down Expand Up @@ -124,7 +124,7 @@
service('request_stack'),
service(Formatter::class),
service('contao.routing.scope_matcher'),
service('security.helper'),
service('security_token_storage'),
service('twig'),
])
;
Expand Down
12 changes: 7 additions & 5 deletions src/EventListener/Backend/DataContainer/LanguageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

namespace Terminal42\NotificationCenterBundle\EventListener\Backend\DataContainer;

use Contao\BackendUser;
use Contao\CoreBundle\DependencyInjection\Attribute\AsCallback;
use Contao\CoreBundle\Intl\Locales;
use Contao\DataContainer;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Types\Types;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Contracts\Translation\TranslatorInterface;
use Terminal42\NotificationCenterBundle\Backend\AutoSuggester;
use Terminal42\NotificationCenterBundle\Config\ConfigLoader;
Expand All @@ -25,7 +25,7 @@ public function __construct(
private ConfigLoader $configLoader,
private Locales $locales,
private TranslatorInterface $translator,
private Security $security,
private RequestStack $requestStack,
) {
}

Expand All @@ -44,8 +44,10 @@ public function onLoadCallback(DataContainer $dc): void
$GLOBALS['TL_DCA']['tl_nc_language']['palettes']['default'] = $GLOBALS['TL_DCA']['tl_nc_language']['palettes'][$gateway->getType()];
}

if (($user = $this->security->getUser()) instanceof BackendUser) {
$GLOBALS['TL_DCA']['tl_nc_language']['fields']['language']['default'] = $user->language;
$request = $this->requestStack->getCurrentRequest();

if ($request instanceof Request) {
$GLOBALS['TL_DCA']['tl_nc_language']['fields']['language']['default'] = $request->getLocale();
}

if (
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/Backend/DataContainer/MessageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Contao\CoreBundle\Intl\Locales;
use Contao\DataContainer;
use Doctrine\DBAL\Connection;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\HttpFoundation\RequestStack;
use Terminal42\NotificationCenterBundle\Backend\AutoSuggester;
use Terminal42\NotificationCenterBundle\Config\ConfigLoader;
use Twig\Environment;
Expand All @@ -22,7 +22,7 @@ public function __construct(
private readonly ConfigLoader $configLoader,
private readonly ContaoFramework $framework,
private readonly Connection $connection,
private readonly Security $security,
private readonly RequestStack $requestStack,
private readonly Environment $twig,
private readonly Locales $locales,
) {
Expand All @@ -39,7 +39,7 @@ public function onChildRecordCallback(array $row): string
}

$gateway = $this->configLoader->loadGateway($message->getGateway());
$languageNames = $this->locales->getLocales($this->security->getUser()?->language ?? null);
$languageNames = $this->locales->getLocales($this->requestStack->getCurrentRequest()?->getLocale());

$query = $this->connection->createQueryBuilder()
->select('id, language')
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/UpdatePersonalDataListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Soundasleep\Html2Text;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Terminal42\NotificationCenterBundle\NotificationCenter;
use Twig\Environment;

Expand All @@ -26,7 +26,7 @@ public function __construct(
private readonly RequestStack $requestStack,
private readonly Formatter $formatter,
private readonly ScopeMatcher $scopeMatcher,
private readonly Security $security,
private readonly TokenStorageInterface $tokenStorage,
private readonly Environment $twig,
) {
}
Expand All @@ -35,7 +35,7 @@ public function __construct(
public function storePersonalData(): void
{
$request = $this->requestStack->getCurrentRequest();
$user = $this->security->getUser();
$user = $this->tokenStorage->getToken()?->getUser();

if (!$request instanceof Request || !$this->scopeMatcher->isFrontendRequest($request) || !$user instanceof FrontendUser) {
return;
Expand Down
Loading