2323use Hofff \Contao \ContactProfiles \Model \Profile \ProfileRepository ;
2424use Netzmacht \Contao \Toolkit \Dca \DcaManager ;
2525use RuntimeException ;
26- use Symfony \Component \HttpFoundation \Session \SessionInterface ;
26+ use Symfony \Component \HttpFoundation \RequestStack ;
27+ use Symfony \Component \HttpFoundation \Session \Session ;
2728use Symfony \Contracts \Translation \TranslatorInterface ;
2829
2930use 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 ' ) {
0 commit comments