mirror of
https://github.com/getgrav/grav.git
synced 2026-03-04 19:41:36 +01:00
If an array field has ignore_empty: true, only save options with a value
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
1. [](#improved)
|
||||
* Added alias `selfupdate` to the `self-upgrade` `bin/gpm` CLI command
|
||||
* Add `ignore_empty` property to be used on array fields, if positive only save options with a value
|
||||
|
||||
# v1.1.9-rc.2
|
||||
## 11/26/2016
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
namespace Grav\Common\Data;
|
||||
|
||||
use Grav\Common\Grav;
|
||||
use Grav\Common\Utils;
|
||||
use Symfony\Component\Yaml\Exception\ParseException;
|
||||
use Symfony\Component\Yaml\Parser;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
@@ -569,6 +570,7 @@ class Validation
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
if ($options) {
|
||||
$useKey = isset($field['use']) && $field['use'] == 'keys';
|
||||
foreach ($values as $key => $value) {
|
||||
@@ -586,6 +588,18 @@ class Validation
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($field['ignore_empty']) && Utils::isPositive($field['ignore_empty'])) {
|
||||
foreach ($values as $key => $value) {
|
||||
foreach ($value as $inner_key => $inner_value) {
|
||||
if ($inner_value == '') {
|
||||
unset($value[$inner_key]);
|
||||
}
|
||||
}
|
||||
|
||||
$values[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
return $values;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user