From fb500d3e1cc0cbced1d6c01d28ca5d6e8fd3db71 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Wed, 21 Oct 2015 11:09:29 +0200 Subject: [PATCH] Handle saving a new group --- system/src/Grav/Common/User/Group.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/system/src/Grav/Common/User/Group.php b/system/src/Grav/Common/User/Group.php index e71370822..907f2ac40 100644 --- a/system/src/Grav/Common/User/Group.php +++ b/system/src/Grav/Common/User/Group.php @@ -30,6 +30,16 @@ class Group extends Data return $groups; } + /** + * Checks if a group exists + * + * @return object + */ + public static function group_exists($groupname) + { + return isset(self::groups()[$groupname]); + } + /** * Get a group by name * @@ -37,7 +47,11 @@ class Group extends Data */ public static function load($groupname) { - $content = self::groups()[$groupname]; + if (self::group_exists($groupname)) { + $content = self::groups()[$groupname]; + } else { + $content = []; + } $blueprints = new Blueprints('blueprints://'); $blueprint = $blueprints->get('user/group'); @@ -83,7 +97,9 @@ class Group extends Data foreach($fields as $field) { if ($field['type'] == 'text') { $value = $field['name']; - self::getGrav()['config']->set("site.groups.$this->groupname.$value", $this->items[$field['name']]); + if (isset($this->items[$value])) { + self::getGrav()['config']->set("site.groups.$this->groupname.$value", $this->items[$value]); + } } if ($field['type'] == 'array') { $value = $field['name'];