mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add clear option to Flash Message
To give user the option to disable Stacking of messages and being consistent with 3.x
This commit is contained in:
parent
924d382bb3
commit
e1c5ef9e7a
2 changed files with 19 additions and 1 deletions
|
@ -38,6 +38,7 @@ class FlashComponent extends Component {
|
|||
'key' => 'flash',
|
||||
'element' => 'default',
|
||||
'params' => array(),
|
||||
'clear' => false
|
||||
);
|
||||
|
||||
/**
|
||||
|
@ -82,7 +83,10 @@ class FlashComponent extends Component {
|
|||
}
|
||||
$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 @@ class FlashComponentTest extends CakeTestCase {
|
|||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue