diff --git a/CHANGELOG.md b/CHANGELOG.md index 769ac0964..399324517 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ 1. [](#improved) * Better support for Symfony local server `symfony server:start` * Make `Route` objects immutable + * `FlexDirectory::getObject()` can now be called without any parameters to create a new object 1. [](#bugfix) * Fixed `Form` not to use deleted flash object until the end of the request fixing issues with reset * Fixed `FlexForm` to allow multiple form instances with non-existing objects diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index c75a90152..bc48367b6 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -222,7 +222,7 @@ class FlexDirectory implements FlexAuthorizeInterface } /** - * Returns an object if it exists. + * Returns an object if it exists. If no arguments are passed (or both of them are null), method creates a new empty object. * * Note: It is not safe to use the object without checking if the user can access it. * @@ -230,8 +230,12 @@ class FlexDirectory implements FlexAuthorizeInterface * @param string|null $keyField Field to be used as the key. * @return FlexObjectInterface|null */ - public function getObject($key, string $keyField = null): ?FlexObjectInterface + public function getObject($key = null, string $keyField = null): ?FlexObjectInterface { + if (null === $key && null === $keyField) { + return $this->createObject([], ''); + } + return $this->getIndex(null, $keyField)->get($key); }