From 9a307dedd4cbed74fff42a7e79526adfd81d9c2f Mon Sep 17 00:00:00 2001 From: Taras Kruts Date: Thu, 10 Nov 2016 16:28:35 +0200 Subject: [PATCH] Issue 2826357 by ribel: Fixed fatal error when session does not exists yet. --- src/Entity/Flagging.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Entity/Flagging.php b/src/Entity/Flagging.php index 78c92ca..4234e84 100644 --- a/src/Entity/Flagging.php +++ b/src/Entity/Flagging.php @@ -182,10 +182,11 @@ class Flagging extends ContentEntityBase implements FlaggingInterface { */ public function postSave(EntityStorageInterface $storage, $update = TRUE) { if ($this->uid->entity && $this->uid->entity->isAnonymous()) { - $session = \Drupal::request()->getSession(); - $session_flaggings = $session->get('flaggings', []); - $session_flaggings[] = $this->id(); - $session->set('flaggings', $session_flaggings); + if ($session = \Drupal::request()->getSession()) { + $session_flaggings = $session->get('flaggings', []); + $session_flaggings[] = $this->id(); + $session->set('flaggings', $session_flaggings); + } } parent::postSave($storage, $update); -- 2.6.1