Skip to content

fix: check if session if available #478

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

Merged
merged 1 commit into from
Sep 2, 2022
Merged
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
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