Flex User: make multiple file/image fields to work

This commit is contained in:
Matias Griese
2020-09-25 15:03:15 +03:00
parent 614bc0b254
commit 0e34628c6f
3 changed files with 28 additions and 22 deletions

View File

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

View File

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

View File

@@ -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];
}
/**