From b5e26133a77a14f3db9f9414e35635e4f60fcca4 Mon Sep 17 00:00:00 2001 From: Matias Griese Date: Tue, 2 Jul 2019 20:27:12 +0300 Subject: [PATCH] Fixed new Flex User creation not being possible because of username could not be given --- CHANGELOG.md | 1 + system/blueprints/user/account_new.yaml | 2 ++ system/blueprints/user/accounts.yaml | 8 ++++++ system/src/Grav/Common/User/FlexUser/User.php | 26 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a80331d8f..5994552b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * Fixed `url()` not returning a path to non-existing file (`user-data://shop` => `/user/data/shop`) if it is set to fail gracefully * Fixed `url()` returning false on unknown streams, such as `ftp://domain.com`, they should be treated as external URL * Fixed Flex User to have permissions to save and delete his own user + * Fixed new Flex User creation not being possible because of username could not be given # v1.6.11 ## 06/21/2019 diff --git a/system/blueprints/user/account_new.yaml b/system/blueprints/user/account_new.yaml index 6c6505bdb..7a9251851 100644 --- a/system/blueprints/user/account_new.yaml +++ b/system/blueprints/user/account_new.yaml @@ -12,5 +12,7 @@ form: type: text label: PLUGIN_ADMIN.USERNAME help: PLUGIN_ADMIN.USERNAME_HELP + unset-disabled@: true + unset-readonly@: true validate: required: true diff --git a/system/blueprints/user/accounts.yaml b/system/blueprints/user/accounts.yaml index 892a14a25..1c17d8210 100644 --- a/system/blueprints/user/accounts.yaml +++ b/system/blueprints/user/accounts.yaml @@ -27,3 +27,11 @@ config: title: Accounts icon: fa-users authorize: ['admin.users', 'admin.accounts', 'admin.super'] + +form: + fields: + username: + flex-disabled@: exists + flex-readonly@: exists + validate: + required: true \ No newline at end of file diff --git a/system/src/Grav/Common/User/FlexUser/User.php b/system/src/Grav/Common/User/FlexUser/User.php index fe3a3f21f..e95992aae 100644 --- a/system/src/Grav/Common/User/FlexUser/User.php +++ b/system/src/Grav/Common/User/FlexUser/User.php @@ -9,6 +9,7 @@ namespace Grav\Common\User\FlexUser; +use Grav\Common\Data\Blueprint; use Grav\Common\Grav; use Grav\Common\Media\Interfaces\MediaCollectionInterface; use Grav\Common\Page\Media; @@ -381,6 +382,31 @@ class User extends FlexObject implements UserInterface, MediaManipulationInterfa return $this->getBlueprint()->extra($this->toArray()); } + /** + * @param string $name + * @return Blueprint + */ + public function getBlueprint(string $name = '') + { + $blueprint = clone parent::getBlueprint($name); + + $blueprint->addDynamicHandler('flex', function (array &$field, $property, array &$call) { + $params = (array)$call['params']; + $method = array_shift($params); + + if (method_exists($this, $method)) { + $value = $this->{$method}(...$params); + if (\is_array($value) && isset($field[$property]) && \is_array($field[$property])) { + $field[$property] = array_merge_recursive($field[$property], $value); + } else { + $field[$property] = $value; + } + } + }); + + return $blueprint->init(); + } + /** * Return unmodified data as raw string. *