mirror of
https://github.com/getgrav/grav.git
synced 2026-03-01 10:01:26 +01:00
Flex User: make multiple file/image fields to work
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
* 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
|
||||
* Fixed `Flex User` avatar when using folder storage, also allow multiple images
|
||||
|
||||
# v1.7.0-rc.16
|
||||
## 09/01/2020
|
||||
|
||||
@@ -281,7 +281,8 @@ class UserObject extends FlexObject implements UserInterface, \Countable
|
||||
{
|
||||
$value = parent::getFormValue($name, null, $separator);
|
||||
|
||||
if ($name === 'avatar') {
|
||||
$settings = $this->getFieldSettings($name);
|
||||
if ($settings['media_field'] ?? false === true) {
|
||||
return $this->parseFileProperty($value);
|
||||
}
|
||||
|
||||
|
||||
@@ -68,6 +68,30 @@ trait FlexMediaTrait
|
||||
return $media;
|
||||
}
|
||||
|
||||
protected function getFieldSettings(string $field): ?array
|
||||
{
|
||||
if ($field === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Load settings for the field.
|
||||
$schema = $this->getBlueprint()->schema();
|
||||
$settings = $schema ? $schema->getProperty($field) : null;
|
||||
|
||||
if (isset($settings['type']) && \in_array($settings['type'], ['avatar', 'file', 'pagemedia'])) {
|
||||
// Set destination folder.
|
||||
$settings['media_field'] = true;
|
||||
if (empty($settings['destination']) || \in_array($settings['destination'], ['@self', 'self@', '@self@'], true)) {
|
||||
$settings['destination'] = $this->getMediaFolder();
|
||||
$settings['self'] = true;
|
||||
} else {
|
||||
$settings['self'] = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $field
|
||||
* @return array
|
||||
@@ -75,26 +99,7 @@ trait FlexMediaTrait
|
||||
*/
|
||||
protected function getMediaFieldSettings(string $field): array
|
||||
{
|
||||
// Load settings for the field.
|
||||
$schema = $this->getBlueprint()->schema();
|
||||
if ($field && $schema) {
|
||||
$settings = (array)$schema->getProperty($field);
|
||||
} else {
|
||||
$settings = [
|
||||
'accept' => '*',
|
||||
'limit' => 1000
|
||||
];
|
||||
}
|
||||
|
||||
// Set destination folder.
|
||||
if (empty($settings['destination']) || in_array($settings['destination'], ['@self', 'self@', '@self@'], true)) {
|
||||
$settings['destination'] = $this->getMediaFolder();
|
||||
$settings['self'] = true;
|
||||
} else {
|
||||
$settings['self'] = false;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
return $this->getFieldSettings($field) ?? ['accept' => '*', 'limit' => 1000];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user