diff --git a/CHANGELOG.md b/CHANGELOG.md index f79463417..8b8b43b80 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ 1. [](#bugfix) * Regression: Fixed fatal error in blueprints [#2811](https://github.com/getgrav/grav/issues/2811) * Regression: Fixed bad method call in FlexDirectory::getAuthorizeRule() + * Regression: Fixed fatal error in admin if the site has custom permissions in `onAdminRegisterPermissions` # v1.7.0-rc.5 ## 02/03/2020 diff --git a/system/src/Grav/Framework/Acl/Action.php b/system/src/Grav/Framework/Acl/Action.php index 8b35afe27..888eec0e8 100644 --- a/system/src/Grav/Framework/Acl/Action.php +++ b/system/src/Grav/Framework/Acl/Action.php @@ -9,6 +9,8 @@ namespace Grav\Framework\Acl; +use Grav\Common\Inflector; + /** * Class Action * @package Grav\Framework\Acl @@ -37,10 +39,20 @@ class Action implements \IteratorAggregate, \Countable */ public function __construct(string $name, array $action = []) { + $label = $action['label'] ?? null; + if (!$label) { + if ($pos = strrpos($name, '.')) { + $label = substr($name, $pos + 1); + } else { + $label = $name; + } + $label = Inflector::humanize($label, 'all'); + } + $this->name = $name; $this->type = $action['type'] ?? 'action'; $this->visible = (bool)($action['visible'] ?? true); - $this->label = $action['label'] ?? null; + $this->label = $label; unset($action['type'], $action['label']); $this->params = $action; diff --git a/system/src/Grav/Framework/Acl/Permissions.php b/system/src/Grav/Framework/Acl/Permissions.php index 19874c1eb..de6286d3d 100644 --- a/system/src/Grav/Framework/Acl/Permissions.php +++ b/system/src/Grav/Framework/Acl/Permissions.php @@ -212,12 +212,12 @@ class Permissions implements \ArrayAccess, \Countable, \IteratorAggregate protected function getParent(string $name): ?Action { if ($pos = strrpos($name, '.')) { - $name = substr($name, 0, $pos); + $parentName = substr($name, 0, $pos); - $parent = $this->getAction($name); + $parent = $this->getAction($parentName); if (!$parent) { - // TODO: create parent action(s) on the fly - throw new \RuntimeException(__METHOD__ . '(): Adding child action before parent is not supported'); + $parent = new Action($parentName); + $this->addAction($parent); } return $parent;