Upgrade to 3.7.1

This commit is contained in:
Bastian Allgeier
2022-07-12 13:33:21 +02:00
parent 7931eb5e47
commit 1ad1eaf387
377 changed files with 63981 additions and 63824 deletions

View File

@@ -16,42 +16,42 @@ use Kirby\Toolkit\Collection;
*/
class Fields extends Collection
{
/**
* Internal setter for each object in the Collection.
* This takes care of validation and of setting
* the collection prop on each object correctly.
*
* @param string $name
* @param object|array $field
* @return $this
*/
public function __set(string $name, $field)
{
if (is_array($field) === true) {
// use the array key as name if the name is not set
$field['name'] ??= $name;
$field = Field::factory($field['type'], $field, $this);
}
/**
* Internal setter for each object in the Collection.
* This takes care of validation and of setting
* the collection prop on each object correctly.
*
* @param string $name
* @param object|array $field
* @return void
*/
public function __set(string $name, $field): void
{
if (is_array($field) === true) {
// use the array key as name if the name is not set
$field['name'] ??= $name;
$field = Field::factory($field['type'], $field, $this);
}
return parent::__set($field->name(), $field);
}
parent::__set($field->name(), $field);
}
/**
* Converts the fields collection to an
* array and also does that for every
* included field.
*
* @param \Closure|null $map
* @return array
*/
public function toArray(Closure $map = null): array
{
$array = [];
/**
* Converts the fields collection to an
* array and also does that for every
* included field.
*
* @param \Closure|null $map
* @return array
*/
public function toArray(Closure $map = null): array
{
$array = [];
foreach ($this as $field) {
$array[$field->name()] = $field->toArray();
}
foreach ($this as $field) {
$array[$field->name()] = $field->toArray();
}
return $array;
}
return $array;
}
}