mirror of
https://github.com/getgrav/grav.git
synced 2026-07-20 04:41:14 +02:00
Fixed FlexForm::updateObject() to update array values when they are empty in the form
This commit is contained in:
@@ -9,7 +9,11 @@
|
||||
* Added `onPageAction`, `onPageTask`, `onPageAction.{$action}` and `onPageTask.{$task}` events
|
||||
* Added `Blueprint::processForm()` method to filter form inputs
|
||||
* Move `processMarkdown()` method from `TwigExtension` to more general `Utils` class
|
||||
|
||||
1. [](#improved)
|
||||
* Add method argument `Data::filter($missingValuesAsNull)`, defaulting to `false`
|
||||
1. [](#bugfix)
|
||||
* Fixed `FlexForm::updateObject()` to update array values when they are empty in the form
|
||||
|
||||
# v1.6.0-beta.7
|
||||
## 12/14/2018
|
||||
|
||||
|
||||
@@ -119,13 +119,14 @@ class Blueprint extends BlueprintForm
|
||||
* Filter data by using blueprints.
|
||||
*
|
||||
* @param array $data
|
||||
* @param bool $missingValuesAsNull
|
||||
* @return array
|
||||
*/
|
||||
public function filter(array $data)
|
||||
public function filter(array $data, bool $missingValuesAsNull = false)
|
||||
{
|
||||
$this->initInternals();
|
||||
|
||||
return $this->blueprintSchema->filter($data);
|
||||
return $this->blueprintSchema->filter($data, $missingValuesAsNull);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -196,12 +196,13 @@ class Data implements DataInterface, \ArrayAccess, \Countable, \JsonSerializable
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $missingValuesAsNull
|
||||
* @return $this
|
||||
* Filter all items by using blueprints.
|
||||
*/
|
||||
public function filter()
|
||||
public function filter(bool $missingValuesAsNull = false)
|
||||
{
|
||||
$this->items = $this->blueprints()->filter($this->items);
|
||||
$this->items = $this->blueprints()->filter($this->items, $missingValuesAsNull);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -597,9 +597,13 @@ class Validation
|
||||
|
||||
if (isset($field['ignore_empty']) && Utils::isPositive($field['ignore_empty'])) {
|
||||
foreach ($values as $key => $val) {
|
||||
foreach ($val as $inner_key => $inner_value) {
|
||||
if ($inner_value == '') {
|
||||
unset($val[$inner_key]);
|
||||
if ($val === '') {
|
||||
unset($values[$key]);
|
||||
} elseif (\is_array($val)) {
|
||||
foreach ($val as $inner_key => $inner_value) {
|
||||
if ($inner_value === '') {
|
||||
unset($val[$inner_key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,15 +755,12 @@ class Validation
|
||||
|
||||
protected static function filterInt($value, $params)
|
||||
{
|
||||
return (int) $value;
|
||||
return (int)$value;
|
||||
}
|
||||
|
||||
public static function validateArray($value, $params)
|
||||
{
|
||||
return \is_array($value)
|
||||
|| ($value instanceof \ArrayAccess
|
||||
&& $value instanceof \Traversable
|
||||
&& $value instanceof \Countable);
|
||||
return \is_array($value) || ($value instanceof \ArrayAccess && $value instanceof \Traversable && $value instanceof \Countable);
|
||||
}
|
||||
|
||||
public static function filterItem_List($value, $params)
|
||||
|
||||
@@ -246,4 +246,16 @@ class FlexForm implements FlexFormInterface
|
||||
|
||||
$this->object = $data['object'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter validated data.
|
||||
*
|
||||
* @param \ArrayAccess $data
|
||||
*/
|
||||
protected function filterData(\ArrayAccess $data): void
|
||||
{
|
||||
if ($data instanceof Data) {
|
||||
$data->filter(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user