Aura.Session
Aura.Session copied to clipboard
[4.x] Add "All Getters" for "Flash" values and "Add"
This is just #47 for 3.x.
It looks like there was already a getAll
equivalent: getSegment
.
Fair point, @harikt. Perhaps the name is a little terse.
Perhaps getAllCurrentFlash()
, and getAllNextFlash()
would be better?
Let's wait to hear from pmjones thoughts.
I added "add" methods here as well.
I should have perhaps done this as a separate PR, but the intention is that the getAll
and add
stuff would be complimentary.
@harikt, I just noticed that you said to wait on pmj, but i'm pretty sure you're right, so I had already gone and changed it. Obviously can always change to something else.
As an illustration of my intended use case:
<?php
// @codingStandardsIgnoreFile
abstract class MyAbstractResponder
{
protected $msgSegment = 'My\\Messages';
protected function addMessage($msg, $level = 'info')
{
$this->getSession()
->getSegment($this->msgSegment)
->addFlash(['lvl' => $level, 'msg' => $msg]);
}
protected function getMessages()
{
return $this->getSession()
->getSegment($this->msgSegment)
->getAllCurrentFlash([]);
}
protected function render()
{
$view = $this->getView();
$view->addData(['messages' => $this->getMessages()]);
$this->response->getBody()->write($view());
}
protected function updated()
{
$this->addMessage('Successfully updated thing', 'success');
$this->redirect();
}
//...
}
@jakejohns Sorry that this is not merged. I am going to release a 4.x for session to make it compatible with 8.x . Newer feature is not incorported for now. So this is currently put on hold.