diff --git a/CHANGELOG.md b/CHANGELOG.md index 57a7b8a39..07b233996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/system/src/Grav/Common/Flex/Types/Users/UserObject.php b/system/src/Grav/Common/Flex/Types/Users/UserObject.php index e23bb8699..14d714282 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserObject.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserObject.php @@ -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); } diff --git a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php index 551f45434..e1ec20641 100644 --- a/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php +++ b/system/src/Grav/Framework/Flex/Traits/FlexMediaTrait.php @@ -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]; } /**