Skip to content
Permalink
Browse files

Use default flash element.

  • Loading branch information...
ADmad committed Jul 13, 2014
1 parent 1ff7bf5 commit c50e730d2f9bbad75e4b6ee9107465d1c5ae8468
@@ -40,7 +40,7 @@ class FlashComponent extends Component {
*/
protected $_defaultConfig = [
'key' => 'flash',
'element' => null,
'element' => 'default',
'params' => []
];
@@ -63,7 +63,7 @@ public function __construct(ComponentRegistry $collection, array $config = []) {
* ### Options:
*
* - `key` The key to set under the session's Flash key
* - `element` The element used to render the flash message
* - `element` The element used to render the flash message. Default to 'default'.
* - `params` An array of variables to make available when using an element
*
* @param string|\Exception $message Message to be flashed. If an instance
@@ -80,14 +80,12 @@ public function set($message, array $options = []) {
$message = $message->getMessage();
}
if ($opts['element'] !== null) {
list($plugin, $element) = pluginSplit($opts['element']);
list($plugin, $element) = pluginSplit($opts['element']);
if ($plugin) {
$opts['element'] = $plugin . '.Flash/' . $element;
} else {
$opts['element'] = 'Flash/' . $element;
}
if ($plugin) {
$opts['element'] = $plugin . '.Flash/' . $element;
} else {
$opts['element'] = 'Flash/' . $element;
}
$this->_session->write('Flash.' . $opts['key'], [
@@ -62,18 +62,12 @@ class FlashHelper extends Helper {
* @return string
*/
public function render($key = 'flash', array $options = []) {
$flash = $this->request->session()->read("Flash.$key");
$this->request->session()->delete("Flash.$key");
if (!$flash) {
if (!$this->request->session()->check("Flash.$key")) {
return '';
}
$flash = $options + $flash;
if ($flash['element'] === null) {
return $flash['message'];
}
$flash = $options + $this->request->session()->read("Flash.$key");
$this->request->session()->delete("Flash.$key");
return $this->_View->element($flash['element'], $flash);
}
@@ -65,7 +65,7 @@ public function testSet() {
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => null,
'element' => 'Flash/default',
'params' => []
];
$result = $this->Session->read('Flash.flash');
@@ -95,7 +95,7 @@ public function testSet() {
$expected = [
'message' => 'This is a test message',
'key' => 'foobar',
'element' => null,
'element' => 'Flash/default',
'params' => []
];
$result = $this->Session->read('Flash.foobar');
@@ -115,7 +115,7 @@ public function testSetWithException() {
$expected = [
'message' => 'This is a test message',
'key' => 'flash',
'element' => null,
'element' => 'Flash/default',
'params' => ['code' => 404]
];
$result = $this->Session->read('Flash.flash');
@@ -46,7 +46,7 @@ public function setUp() {
'flash' => array(
'key' => 'flash',
'message' => 'This is a calling',
'element' => null,
'element' => 'Flash/default',
'params' => array()
),
'notification' => array(
@@ -75,7 +75,7 @@ public function setUp() {
*/
public function tearDown() {
parent::tearDown();
unset($this->View, $this->Session);
unset($this->View, $this->Flash);
}
/**
@@ -85,8 +85,8 @@ public function tearDown() {
*/
public function testFlash() {
$result = $this->Flash->render();
$expected = 'This is a calling';
$this->assertEquals($expected, $result);
$expected = '<div class="message">This is a calling</div>';
$this->assertContains($expected, $result);
$expected = '<div id="classy-message">Recorded</div>';
$result = $this->Flash->render('classy');
@@ -0,0 +1 @@
<div class="message"><?= $message; ?></div>

0 comments on commit c50e730

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