Compare commits

...

9 Commits
1.7.6 ... 1.7.7

Author SHA1 Message Date
Andy Miller
061a65f730 Merge branch 'release/1.7.7' 2021-02-23 15:02:18 -07:00
Andy Miller
7db4da4154 prepare for release 2021-02-23 15:02:08 -07:00
Matias Griese
78b5f6ef5c Fixed typo #3233 2021-02-22 18:53:57 +02:00
Matias Griese
340f478bfa Improved Pagination class to allow custom pagination query parameter 2021-02-22 14:51:14 +02:00
Matias Griese
2108af8f36 Added Utils::arrayToQueryParams() to convert an array into query params 2021-02-22 14:49:23 +02:00
Djamil Legato
1728b6c8bf Updated changelog 2021-02-19 13:42:27 -08:00
Djamil Legato
bbfd514342 Removed special space character 2021-02-19 13:41:20 -08:00
Matias Griese
e42ae65355 Fixed avatar of the user not being saved 2021-02-19 11:29:17 +02:00
Andy Miller
0e8e00ddd7 Merge tag '1.7.6' into develop
Release v1.7.6
2021-02-17 11:36:45 -07:00
8 changed files with 78 additions and 53 deletions

View File

@@ -1,3 +1,15 @@
# v1.7.7
## 02/23/2021
1. [](#new)
* Added `Utils::arrayToQueryParams()` to convert an array into query params
1. [](#improved)
* Added original image support for all flex objects and media fields
* Improved `Pagination` class to allow custom pagination query parameter
1. [](#bugfix)
* Fixed avatar of the user not being saved [grav-plugin-flex-objects#111](https://github.com/trilbymedia/grav-plugin-flex-objects/issues/111)
* Replaced special space character with regular space in `system/blueprints/user/account_new.yaml`
# v1.7.6
## 02/17/2021

View File

@@ -13,6 +13,6 @@ form:
label: PLUGIN_ADMIN.USERNAME
help: PLUGIN_ADMIN.USERNAME_HELP
unset-disabled@: true
unset-readonly@: true
unset-readonly@: true
validate:
required: true

View File

@@ -8,7 +8,7 @@
// Some standard defines
define('GRAV', true);
define('GRAV_VERSION', '1.7.6');
define('GRAV_VERSION', '1.7.7');
define('GRAV_SCHEMA', '1.7.0_2020-11-20_1');
define('GRAV_TESTING', false);

View File

@@ -290,7 +290,8 @@ class UserObject extends FlexObject implements UserInterface, Countable
$value = parent::getProperty($property, $default);
if ($property === 'avatar') {
$value = $this->parseFileProperty($value);
$settings = $this->getMediaFieldSettings($property);
$value = $this->parseFileProperty($value, $settings);
}
return $value;
@@ -304,7 +305,9 @@ class UserObject extends FlexObject implements UserInterface, Countable
public function toArray()
{
$array = $this->jsonSerialize();
$array['avatar'] = $this->parseFileProperty($array['avatar'] ?? null);
$settings = $this->getMediaFieldSettings('avatar');
$array['avatar'] = $this->parseFileProperty($array['avatar'] ?? null, $settings);
return $array;
}
@@ -808,46 +811,6 @@ class UserObject extends FlexObject implements UserInterface, Countable
$this->clearMediaCache();
}
/**
* @param array|mixed $value
* @param array $settings
* @return array|mixed
*/
protected function parseFileProperty($value, array $settings = [])
{
if (!is_array($value)) {
return $value;
}
$originalMedia = $this->getOriginalMedia();
$resizedMedia = $this->getMedia();
$list = [];
foreach ($value as $filename => $info) {
if (!is_array($info)) {
continue;
}
/** @var Medium|null $thumbFile */
$thumbFile = $resizedMedia[$filename];
/** @var Medium|null $imageFile */
$imageFile = $originalMedia[$filename] ?? $thumbFile;
if ($thumbFile && $imageFile) {
$list[$filename] = [
'name' => $info['name'] ?? null,
'type' => $info['type'] ?? null,
'size' => $info['size'] ?? null,
'path' => $info['path'] ?? null,
'image_url' => $imageFile->url(),
'thumb_url' => $thumbFile->url(),
'cropData' => (object)($imageFile->metadata()['upload']['crop'] ?? [])
];
}
}
return $list;
}
/**
* @return array
*/

View File

@@ -39,7 +39,7 @@ class Language
/** @var array */
protected $fallback_extensions = [];
/** @var array */
protected $page_extesions = [];
protected $page_extensions = [];
/** @var string|false */
protected $default;
/** @var string|false */
@@ -400,7 +400,7 @@ class Language
{
$this->fallback_languages = [];
$this->fallback_extensions = [];
$this->page_extesions = [];
$this->page_extensions = [];
}
/**

View File

@@ -1086,6 +1086,29 @@ abstract class Utils
return $result;
}
/**
* Flatten a multi-dimensional associative array into query params.
*
* @param array $array
* @param string $prepend
* @return array
*/
public static function arrayToQueryParams($array, $prepend = '')
{
$results = [];
foreach ($array as $key => $value) {
$name = $prepend ? $prepend . '[' . $key . ']' : $key;
if (is_array($value)) {
$results = array_merge($results, static::arrayToQueryParams($value, $name));
} else {
$results[$name] = $value;
}
}
return $results;
}
/**
* Flatten an array
*

View File

@@ -25,6 +25,8 @@ use RocketTheme\Toolbox\ResourceLocator\UniformResourceLocator;
use RuntimeException;
use function in_array;
use function is_array;
use function is_callable;
use function is_int;
use function is_object;
use function is_string;
use function strpos;
@@ -141,24 +143,38 @@ trait FlexMediaTrait
}
$media = $this->getMedia();
$originalMedia = is_callable([$this, 'getOriginalMedia']) ? $this->getOriginalMedia() : null;
$list = [];
foreach ($value as $filename => $info) {
if (!is_array($info)) {
$list[$filename] = $info;
continue;
}
if (is_int($filename)) {
$filename = $info['path'] ?? $info['name'];
}
/** @var Medium|null $thumbFile */
$imageFile = $media[$filename];
/** @var Medium|null $thumbFile */
$originalFile = $originalMedia ? $originalMedia[$filename] : null;
$url = $imageFile ? $imageFile->url() : null;
$originalUrl = $originalFile ? $originalFile->url() : null;
$list[$filename] = [
'name' => $info['name'] ?? null,
'type' => $info['type'] ?? null,
'size' => $info['size'] ?? null,
'path' => $filename,
'image_url' => $url,
'thumb_url' => $url
'thumb_url' => $url,
'image_url' => $originalUrl ?? $url
];
if ($originalFile) {
$list[$filename]['cropData'] = (object)($originalFile->metadata()['upload']['crop'] ?? []);
}
}
return $list;

View File

@@ -47,7 +47,9 @@ class AbstractPagination implements PaginationInterface
'display' => 5,
'opening' => 0,
'ending' => 0,
'url' => null
'url' => null,
'param' => null,
'use_query_param' => false
];
/** @var array */
private $items;
@@ -126,14 +128,23 @@ class AbstractPagination implements PaginationInterface
}
$start = ($page - 1) * $this->limit;
if ($this->getOptions()['type'] === 'page') {
$name = 'page';
$type = $this->getOptions()['type'];
$param = $this->getOptions()['param'];
$useQuery = $this->getOptions()['use_query_param'];
if ($type === 'page') {
$param = $param ?? 'page';
$offset = $page;
} else {
$name = 'start';
$param = $param ?? 'start';
$offset = $start;
}
if ($useQuery) {
$route = $this->route->withQueryParam($param, $offset);
} else {
$route = $this->route->withGravParam($param, $offset);
}
return new PaginationPage(
[
'label' => $label ?? (string)$page,
@@ -142,7 +153,7 @@ class AbstractPagination implements PaginationInterface
'offset_end' => min($start + $this->limit, $this->total) - 1,
'enabled' => $page !== $this->page || $this->viewAll,
'active' => $page === $this->page,
'route' => $this->route->withGravParam($name, $offset)
'route' => $route
]
);
}