mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Added FormTrait::getAllFlashes() method to get all the available form flash objects for the form
This commit is contained in:
parent
b398d04d96
commit
f695aaaea4
|
|
@ -1,6 +1,8 @@
|
|||
# v1.6.11
|
||||
## mm/dd/2019
|
||||
|
||||
1. [](#new)
|
||||
* Added `FormTrait::getAllFlashes()` method to get all the available form flash objects for the form
|
||||
1. [](#bugfix)
|
||||
* Fixed error in `ImageMedium::url()` if the image cache folder does not exist
|
||||
* Fixed empty form flash name after update
|
||||
|
|
|
|||
|
|
@ -336,35 +336,42 @@ trait FormTrait
|
|||
public function getFlash(): FormFlash
|
||||
{
|
||||
if (null === $this->flash) {
|
||||
/** @var Grav $grav */
|
||||
$grav = Grav::instance();
|
||||
$id = null;
|
||||
|
||||
$user = $grav['user'] ?? null;
|
||||
if (isset($user)) {
|
||||
$rememberState = $this->getBlueprint()->get('form/remember_state');
|
||||
if ($rememberState === 'user') {
|
||||
$id = $user->username;
|
||||
}
|
||||
}
|
||||
|
||||
// Session Required for flash form
|
||||
$session = $grav['session'] ?? null;
|
||||
if (isset($session)) {
|
||||
// By default store flash by the session id.
|
||||
if (null === $id) {
|
||||
$id = $session->getId();
|
||||
}
|
||||
|
||||
$id = $this->getFlashId();
|
||||
|
||||
if ($id) {
|
||||
$this->flash = new FormFlash($id, $this->getUniqueId(), $this->getName());
|
||||
$this->flash->setUrl($grav['uri']->url)->setUser($user);
|
||||
$this->flash->setUrl($grav['uri']->url)->setUser($grav['user'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->flash;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available form flash objects for this form.
|
||||
*
|
||||
* @return FormFlash[]
|
||||
*/
|
||||
public function getAllFlashes(): array
|
||||
{
|
||||
$folder = FormFlash::getSessionTmpDir($this->getFlashId());
|
||||
$name = $this->getName();
|
||||
$id = $this->getFlashId();
|
||||
|
||||
$list = [];
|
||||
/** @var \SplFileInfo $file */
|
||||
foreach (new \FilesystemIterator($folder) as $file) {
|
||||
$flash = new FormFlash($id, $file->getFilename(), $name);
|
||||
if ($flash->exists() && $flash->getFormName() === $name) {
|
||||
$list[] = $flash;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
* @see FormInterface::render()
|
||||
|
|
@ -389,6 +396,32 @@ trait FormTrait
|
|||
return $block;
|
||||
}
|
||||
|
||||
protected function getFlashId(): ?string
|
||||
{
|
||||
/** @var Grav $grav */
|
||||
$grav = Grav::instance();
|
||||
$id = null;
|
||||
|
||||
$user = $grav['user'] ?? null;
|
||||
if (isset($user)) {
|
||||
$rememberState = $this->getBlueprint()->get('form/remember_state');
|
||||
if ($rememberState === 'user') {
|
||||
$id = $user->username;
|
||||
}
|
||||
}
|
||||
|
||||
// Session Required for flash form
|
||||
$session = $grav['session'] ?? null;
|
||||
if (isset($session)) {
|
||||
// By default store flash by the session id.
|
||||
if (null === $id) {
|
||||
$id = $session->getId();
|
||||
}
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
protected function unsetFlash(): void
|
||||
{
|
||||
$this->flash = null;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user