Upgrade to 3.7.0
This commit is contained in:
21
kirby/src/Cms/Content.php
Normal file → Executable file
21
kirby/src/Cms/Content.php
Normal file → Executable file
@@ -60,9 +60,14 @@ class Content
|
||||
*
|
||||
* @param array|null $data
|
||||
* @param object|null $parent
|
||||
* @param bool $normalize Set to `false` if the input field keys are already lowercase
|
||||
*/
|
||||
public function __construct(array $data = [], $parent = null)
|
||||
public function __construct(array $data = [], $parent = null, bool $normalize = true)
|
||||
{
|
||||
if ($normalize === true) {
|
||||
$data = array_change_key_case($data, CASE_LOWER);
|
||||
}
|
||||
|
||||
$this->data = $data;
|
||||
$this->parent = $parent;
|
||||
}
|
||||
@@ -163,9 +168,7 @@ class Content
|
||||
return $this->fields[$key];
|
||||
}
|
||||
|
||||
// fetch the value no matter the case
|
||||
$data = $this->data();
|
||||
$value = $data[$key] ?? array_change_key_case($data)[$key] ?? null;
|
||||
$value = $this->data()[$key] ?? null;
|
||||
|
||||
return $this->fields[$key] = new Field($this->parent, $key, $value);
|
||||
}
|
||||
@@ -178,10 +181,7 @@ class Content
|
||||
*/
|
||||
public function has(string $key): bool
|
||||
{
|
||||
$key = strtolower($key);
|
||||
$data = array_change_key_case($this->data);
|
||||
|
||||
return isset($data[$key]) === true;
|
||||
return isset($this->data[strtolower($key)]) === true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +208,7 @@ class Content
|
||||
$copy->fields = null;
|
||||
|
||||
foreach ($keys as $key) {
|
||||
unset($copy->data[$key]);
|
||||
unset($copy->data[strtolower($key)]);
|
||||
}
|
||||
|
||||
return $copy;
|
||||
@@ -258,7 +258,8 @@ class Content
|
||||
*/
|
||||
public function update(array $content = null, bool $overwrite = false)
|
||||
{
|
||||
$this->data = $overwrite === true ? (array)$content : array_merge($this->data, (array)$content);
|
||||
$content = array_change_key_case((array)$content, CASE_LOWER);
|
||||
$this->data = $overwrite === true ? $content : array_merge($this->data, $content);
|
||||
|
||||
// clear cache of Field objects
|
||||
$this->fields = [];
|
||||
|
Reference in New Issue
Block a user