Skip to content

Commit

Permalink
fix: check if session if available (#478)
Browse files Browse the repository at this point in the history
Co-authored-by: Robbe De Geyndt <[email protected]>
  • Loading branch information
robbedg and Robbe De Geyndt authored Sep 2, 2022
1 parent 1a83e47 commit 692900e
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions EditInPlace/Activator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ public function setSession(Session $session): void
/**
* Get session based on availability.
*/
private function getSession(): Session
private function getSession(): ?Session
{
$session = $this->session;
if (null === $session) {
if (null === $session && $this->requestStack->getCurrentRequest()->hasSession()) {
$session = $this->requestStack->getSession();
}

Expand All @@ -65,23 +65,27 @@ private function getSession(): Session
*/
public function activate(): void
{
$this->getSession()->set(self::KEY, true);
if (null !== $this->getSession()) {
$this->getSession()->set(self::KEY, true);
}
}

/**
* Disable the Edit In Place mode.
*/
public function deactivate(): void
{
$this->getSession()->remove(self::KEY);
if (null !== $this->getSession()) {
$this->getSession()->remove(self::KEY);
}
}

/**
* {@inheritdoc}
*/
public function checkRequest(Request $request = null): bool
{
if (!$this->getSession()->has(self::KEY)) {
if (null === $this->getSession() || !$this->getSession()->has(self::KEY)) {
return false;
}

Expand Down

0 comments on commit 692900e

Please sign in to comment.