Skip to content

Commit dc6400e

Browse files
committed
Do not use removed session service
1 parent 4573f13 commit dc6400e

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/EventListener/Dca/ContactProfileDcaListener.php

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
use Hofff\Contao\ContactProfiles\Model\Profile\ProfileRepository;
2424
use Netzmacht\Contao\Toolkit\Dca\DcaManager;
2525
use RuntimeException;
26-
use Symfony\Component\HttpFoundation\Session\SessionInterface;
26+
use Symfony\Component\HttpFoundation\RequestStack;
27+
use Symfony\Component\HttpFoundation\Session\Session;
2728
use Symfony\Contracts\Translation\TranslatorInterface;
2829

2930
use function func_get_arg;
@@ -40,24 +41,30 @@ final class ContactProfileDcaListener
4041
private string $pattern;
4142

4243
public function __construct(
43-
private SlugGeneratorInterface $slugGenerator,
44-
private Connection $connection,
45-
private ProfileRepository $profiles,
46-
private TranslatorInterface $translator,
47-
private DcaManager $dcaManager,
48-
private SessionInterface $session,
44+
private readonly SlugGeneratorInterface $slugGenerator,
45+
private readonly Connection $connection,
46+
private readonly ProfileRepository $profiles,
47+
private readonly TranslatorInterface $translator,
48+
private readonly DcaManager $dcaManager,
49+
private readonly RequestStack $requestStack,
4950
string $aliasPattern,
50-
private bool $multilingual,
51-
private string|null $fallbackLanguage,
51+
private readonly bool $multilingual,
52+
private readonly string|null $fallbackLanguage,
5253
) {
5354
$this->pattern = $aliasPattern;
5455
}
5556

5657
/** @Callback(table="tl_contact_profile", target="config.onload") */
5758
public function onLoad(): void
5859
{
60+
$request = $this->requestStack->getCurrentRequest();
61+
$session = $request?->getSession();
62+
if (! $session instanceof Session) {
63+
return;
64+
}
65+
5966
/** @psalm-suppress UndefinedInterfaceMethod */
60-
$sorting = $this->session->getBag('contao_backend')->get('sorting')['tl_contact_profile'] ?? null;
67+
$sorting = $this->requestStack->getBag('contao_backend')->get('sorting')['tl_contact_profile'] ?? null;
6168

6269
// Only set sorting as the first field if custom sorting is chosen.
6370
if ($sorting !== 'sorting') {

src/Resources/config/listener.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<argument type="service" id="Hofff\Contao\ContactProfiles\Model\Profile\ProfileRepository"/>
4949
<argument type="service" id="translator"/>
5050
<argument type="service" id="netzmacht.contao_toolkit.dca.manager"/>
51-
<argument type="service" id="session"/>
51+
<argument type="service" id="request_stack"/>
5252
<argument>%hofff_contao_contact_profiles.alias_pattern%</argument>
5353
<argument>%hofff_contao_contact_profiles.multilingual.enable%</argument>
5454
<argument>%hofff_contao_contact_profiles.multilingual.fallback_language%</argument>

0 commit comments

Comments
 (0)