mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 19:15:34 +02:00
Added second parameter to $blueprint->flattenData() to include every field, including those which have no data
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
* Added optional password/database attributes for redis in `system.yaml`
|
||||
* Added ability to filter enabled or disabled with bin/gpm index [#3187](https://github.com/getgrav/grav/pull/3187)
|
||||
* Added `$grav->getVersion()` or `grav.version` in twig to get the current Grav version [#3142](https://github.com/getgrav/grav/issues/3142)
|
||||
* Added second parameter to `$blueprint->flattenData()` to include every field, including those which have no data
|
||||
1. [](#bugfix)
|
||||
* Fixed CLI progressbar in `backup` and `security` commands to use styled output [#3198](https://github.com/getgrav/grav/issues/3198)
|
||||
* Fixed page save failing because of uploaded images [#3191](https://github.com/getgrav/grav/issues/3191)
|
||||
|
||||
@@ -294,13 +294,14 @@ class Blueprint extends BlueprintForm
|
||||
* Flatten data by using blueprints.
|
||||
*
|
||||
* @param array $data
|
||||
* @param bool $includeAll
|
||||
* @return array
|
||||
*/
|
||||
public function flattenData(array $data)
|
||||
public function flattenData(array $data, bool $includeAll = false)
|
||||
{
|
||||
$this->initInternals();
|
||||
|
||||
return $this->blueprintSchema->flattenData($data);
|
||||
return $this->blueprintSchema->flattenData($data, $includeAll);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -107,11 +107,22 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
* Flatten data by using blueprints.
|
||||
*
|
||||
* @param array $data Data to be flattened.
|
||||
* @param bool $includeAll
|
||||
* @return array
|
||||
*/
|
||||
public function flattenData(array $data)
|
||||
public function flattenData(array $data, bool $includeAll = false)
|
||||
{
|
||||
return $this->flattenArray($data, $this->nested, '');
|
||||
$list = [];
|
||||
if ($includeAll) {
|
||||
foreach ($this->items as $key => $rules) {
|
||||
$type = $rules['type'] ?? '';
|
||||
if (!str_starts_with($type, '_')) {
|
||||
$list[$key] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array_replace($list, $this->flattenArray($data, $this->nested, ''));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,6 +150,7 @@ class BlueprintSchema extends BlueprintSchemaBase implements ExportInterface
|
||||
$array[$prefix.$key] = $field;
|
||||
}
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user