Merge branch 'develop' of github.com:getgrav/grav into 1.7

This commit is contained in:
Matias Griese
2019-06-20 01:05:07 +03:00
3 changed files with 60 additions and 23 deletions

View File

@@ -19,9 +19,12 @@
# 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
* Fixed a bug in `Route::withParam()` method
# v1.6.10
## 06/14/2019

View File

@@ -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;

View File

@@ -313,9 +313,9 @@ class Route
*/
protected function withParam($type, $param, $value)
{
$oldValue = $this->{$type}[$param] ?? null;
$typeValue = $this->{$type}[$param] ?? null;
if ($oldValue === $value) {
if ($typeValue === $value) {
return $this;
}
@@ -323,7 +323,8 @@ class Route
if ($value === null) {
unset($new->{$type}[$param]);
} else {
$new->{$type}[$param] = $value;
$typeValue[$param] = $value;
$new->{$type} = $typeValue;
}
return $new;