From 21db2e7d4a4d230d08af443e4fff11f6fa58579e Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Thu, 9 Sep 2021 14:14:16 +0300 Subject: [PATCH] Added support for `flex-required@: not exists` and `flex-required@: '!exists'` in blueprints --- CHANGELOG.md | 1 + .../Common/Flex/Types/UserGroups/UserGroupObject.php | 8 ++++++++ .../src/Grav/Common/Flex/Types/Users/UserObject.php | 8 ++++++++ system/src/Grav/Framework/Flex/FlexDirectory.php | 11 ++++++++++- 4 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8f0d44403..816070a85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ * Added `|yaml` filter to convert input to YAML * Added `route` and `request` to `onPageNotFound` event * Added file upload/remove support for `Flex Forms` + * Added support for `flex-required@: not exists` and `flex-required@: '!exists'` in blueprints * Throwing exceptions from Twig templates fires `onDisplayErrorPage.[code]` event allowing better error pages 3. [](#bugfix) * Fixed escaping in PageIndex::getLevelListing() diff --git a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php index fb69eab68..ea68fa1bf 100644 --- a/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php +++ b/system/src/Grav/Common/Flex/Types/UserGroups/UserGroupObject.php @@ -41,6 +41,14 @@ class UserGroupObject extends FlexObject implements UserGroupInterface ] + parent::getCachedMethods(); } + /** + * @return string + */ + public function getTitle(): string + { + return $this->getProperty('readableName'); + } + /** * Checks user authorization to the action. * diff --git a/system/src/Grav/Common/Flex/Types/Users/UserObject.php b/system/src/Grav/Common/Flex/Types/Users/UserObject.php index c5b3c6f82..310c313fe 100644 --- a/system/src/Grav/Common/Flex/Types/Users/UserObject.php +++ b/system/src/Grav/Common/Flex/Types/Users/UserObject.php @@ -306,6 +306,14 @@ class UserObject extends FlexObject implements UserInterface, Countable return $value; } + /** + * @return UserGroupIndex + */ + public function getRoles(): UserGroupIndex + { + return $this->getGroups(); + } + /** * Convert object into an array. * diff --git a/system/src/Grav/Framework/Flex/FlexDirectory.php b/system/src/Grav/Framework/Flex/FlexDirectory.php index 43fe00081..29f1490f8 100644 --- a/system/src/Grav/Framework/Flex/FlexDirectory.php +++ b/system/src/Grav/Framework/Flex/FlexDirectory.php @@ -836,13 +836,22 @@ class FlexDirectory implements FlexDirectoryInterface $params = (array)$call['params']; $object = $call['object'] ?? null; $method = array_shift($params); + $not = false; + if (str_starts_with($method, '!')) { + $method = substr($method, 1); + $not = true; + } elseif (str_starts_with($method, 'not ')) { + $method = substr($method, 4); + $not = true; + } + $method = trim($method); if ($object && method_exists($object, $method)) { $value = $object->{$method}(...$params); if (is_array($value) && isset($field[$property]) && is_array($field[$property])) { $value = $this->mergeArrays($field[$property], $value); } - $field[$property] = $value; + $field[$property] = $not ? !$value : $value; } }