setMessage($message); $this->setTitle($title); $this->setSeverity($severity); $this->setStoreInSession($storeInSession); } /** * Factory method. Useful when creating flash messages from a jsonSerialize json_decode() call. * * @param array $data */ public static function createFromArray(array $data): self { return GeneralUtility::makeInstance( static::class, (string)($data['message'] ?? ''), (string)($data['title'] ?? ''), ContextualFeedbackSeverity::tryFrom($data['severity'] ?? ContextualFeedbackSeverity::OK->value) ?? ContextualFeedbackSeverity::OK, (bool)($data['storeInSession'] ?? false) ); } /** * Gets the message's storeInSession flag. * * @return bool TRUE if message should be stored in the session, otherwise FALSE. */ public function isSessionMessage() { return $this->storeInSession; } /** * Sets the message's storeInSession flag * * @param bool $storeInSession The persistence flag */ public function setStoreInSession($storeInSession) { $this->storeInSession = (bool)$storeInSession; } /** * @return array Data which can be serialized by json_encode() */ public function jsonSerialize(): array { $data = parent::jsonSerialize(); $data['storeInSession'] = $this->storeInSession; return $data; } }