Skip to content

Commit 692900e

Browse files
robbedgRobbe De Geyndt
andauthored
fix: check if session if available (#478)
Co-authored-by: Robbe De Geyndt <robbe.degeyndt@aware.be>
1 parent 1a83e47 commit 692900e

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

EditInPlace/Activator.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ public function setSession(Session $session): void
5050
/**
5151
* Get session based on availability.
5252
*/
53-
private function getSession(): Session
53+
private function getSession(): ?Session
5454
{
5555
$session = $this->session;
56-
if (null === $session) {
56+
if (null === $session && $this->requestStack->getCurrentRequest()->hasSession()) {
5757
$session = $this->requestStack->getSession();
5858
}
5959

@@ -65,23 +65,27 @@ private function getSession(): Session
6565
*/
6666
public function activate(): void
6767
{
68-
$this->getSession()->set(self::KEY, true);
68+
if (null !== $this->getSession()) {
69+
$this->getSession()->set(self::KEY, true);
70+
}
6971
}
7072

7173
/**
7274
* Disable the Edit In Place mode.
7375
*/
7476
public function deactivate(): void
7577
{
76-
$this->getSession()->remove(self::KEY);
78+
if (null !== $this->getSession()) {
79+
$this->getSession()->remove(self::KEY);
80+
}
7781
}
7882

7983
/**
8084
* {@inheritdoc}
8185
*/
8286
public function checkRequest(Request $request = null): bool
8387
{
84-
if (!$this->getSession()->has(self::KEY)) {
88+
if (null === $this->getSession() || !$this->getSession()->has(self::KEY)) {
8589
return false;
8690
}
8791

0 commit comments

Comments
 (0)