Fixed Flex User avatar when using folder storage

Fixed bug in `Flex Form` making it impossible to set nested values
This commit is contained in:
Matias Griese 2020-09-25 11:08:53 +03:00
parent df4cbdcc09
commit cc6eafdb09
5 changed files with 30 additions and 3 deletions

View File

@ -14,6 +14,8 @@
* Fixed media upload failing with custom folders
* Fixed `unset()` in `ObjectProperty` class
* Fixed `FlexObject::freeMedia()` method causing media to become null
* Fixed bug in `Flex Form` making it impossible to set nested values
* Fixed `Flex User` avatar when using folder storage
# v1.7.0-rc.16
## 09/01/2020

View File

@ -1176,7 +1176,6 @@ form:
validate:
type: bool
media.allowed_fallback_types:
type: selectize
size: large

View File

@ -12,6 +12,7 @@ declare(strict_types=1);
namespace Grav\Common\Flex\Types\Users;
use Grav\Common\Config\Config;
use Grav\Common\Data\Blueprint;
use Grav\Common\Flex\Traits\FlexGravTrait;
use Grav\Common\Flex\Traits\FlexObjectTrait;
use Grav\Common\Flex\Types\Users\Traits\UserObjectLegacyTrait;
@ -630,6 +631,26 @@ class UserObject extends FlexObject implements UserInterface, \Countable
return $folder;
}
/**
* @param string $name
* @return Blueprint
*/
protected function doGetBlueprint(string $name = ''): Blueprint
{
$blueprint = $this->getFlexDirectory()->getBlueprint($name ? '.' . $name : $name);
// HACK: With folder storage we need to ignore the avatar destination.
if ($this->getFlexDirectory()->getMediaFolder()) {
$field = $blueprint->get('form/fields/avatar');
if ($field) {
unset($field['destination']);
$blueprint->set('form/fields/avatar', $field);
}
}
return $blueprint;
}
/**
* @param UserInterface $user
* @param string $action

View File

@ -108,6 +108,9 @@ trait MediaUploadTrait
} else {
// If caller sets the filename, we will accept any custom path.
$folder = dirname($filename);
if ($folder === '.') {
$folder = '';
}
$filename = basename($filename);
}
$extension = pathinfo($filename, PATHINFO_EXTENSION);
@ -115,7 +118,7 @@ trait MediaUploadTrait
// Decide which filename to use.
if ($settings['random_name']) {
// Generate random filename if asked for.
$filename = Utils::generateRandomString(15) . '.' . $extension;
$filename = mb_strtolower(Utils::generateRandomString(15) . '.' . $extension);
}
// Handle conflicting filename if needed.
@ -387,7 +390,6 @@ trait MediaUploadTrait
$locator = $this->getGrav()['locator'];
$fromPath = $path . '/' . $from;
if ($locator->isStream($fromPath)) {
$fromPath = $locator->findResource($fromPath, true, true);
}

View File

@ -40,6 +40,9 @@ class FlexForm implements FlexObjectFormInterface, \JsonSerializable
FormTrait::doUnserialize as doTraitUnserialize;
}
/** @var array */
private $items = [];
/** @var array|null */
private $form;