Chris@14: flashBag = $flash_bag; Chris@14: $this->killSwitch = $killSwitch; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function addError($message, $repeat = FALSE) { Chris@14: return $this->addMessage($message, static::TYPE_ERROR, $repeat); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function addMessage($message, $type = self::TYPE_STATUS, $repeat = FALSE) { Chris@14: if (!($message instanceof Markup) && $message instanceof MarkupInterface) { Chris@14: $message = Markup::create((string) $message); Chris@14: } Chris@14: Chris@14: // Do not use strict type checking so that equivalent string and Chris@14: // MarkupInterface objects are detected. Chris@14: if ($repeat || !in_array($message, $this->flashBag->peek($type))) { Chris@14: $this->flashBag->add($type, $message); Chris@14: } Chris@14: Chris@14: // Mark this page as being uncacheable. Chris@14: $this->killSwitch->trigger(); Chris@14: Chris@14: return $this; Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function addStatus($message, $repeat = FALSE) { Chris@14: return $this->addMessage($message, static::TYPE_STATUS, $repeat); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function addWarning($message, $repeat = FALSE) { Chris@14: return $this->addMessage($message, static::TYPE_WARNING, $repeat); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function all() { Chris@14: return $this->flashBag->peekAll(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function deleteAll() { Chris@14: return $this->flashBag->clear(); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function deleteByType($type) { Chris@14: // Flash bag gets and clears flash messages from the stack. Chris@14: return $this->flashBag->get($type); Chris@14: } Chris@14: Chris@14: /** Chris@14: * {@inheritdoc} Chris@14: */ Chris@14: public function messagesByType($type) { Chris@14: return $this->flashBag->peek($type); Chris@14: } Chris@14: Chris@14: }