Skip to content
Permalink
Browse files

Add clear option to Flash Message

To give user the option to disable Stacking of messages and being consistent with 3.x
  • Loading branch information...
xhs345 committed Oct 31, 2016
1 parent 924d382 commit e1c5ef9e7a6e0a2aef960b90202338864d4ba30c
@@ -38,6 +38,7 @@ class FlashComponent extends Component {
'key' => 'flash',
'element' => 'default',
'params' => array(),
'clear' => false
);
/**
@@ -82,7 +83,10 @@ public function set($message, $options = array()) {
}
$options['element'] = $plugin . 'Flash/' . $element;
$messages = CakeSession::read('Message.' . $options['key']);
$messages = array();
if ($options['clear'] === false) {
$messages = (array)CakeSession::read('Message.' . $options['key']);
}
$newMessage = array(
'message' => $message,
@@ -131,6 +131,20 @@ public function testSet() {
$result = CakeSession::read('Message.foobar');
$this->assertEquals($expected, $result);
CakeSession::delete('Message.foobar');
$this->Flash->set('This is the first message');
$this->Flash->set('This is the second message', array('clear' => true));
$expected = array(
array(
'message' => 'This is the second message',
'key' => 'flash',
'element' => 'Flash/default',
'params' => array()
)
);
$result = CakeSession::read('Message.flash');
$this->assertEquals($expected, $result);
CakeSession::delete('Message.flash');
}
/**

0 comments on commit e1c5ef9

Please sign in to comment.
You can’t perform that action at this time.