new Plugin::upstreamConfigVar

This commit is contained in:
Andy Miller 2021-12-18 17:46:55 -07:00
parent 5bec5db5e1
commit 8343cfb278
No known key found for this signature in database
GPG Key ID: 9F2CF38AEBDB0AE0
2 changed files with 25 additions and 0 deletions

View File

@ -7,6 +7,7 @@
* Added second parameter to `UserObject::isMyself()` method
* Added `UserObject::$isAuthorizedCallable` to allow `$user->isAuthorized()` customization
* Use secure session cookies in HTTPS by default (`system.session.secure_https: true`)
* Added new `Plugin::upstreamConfigVar()` function to access plugin specific functions for page overrides
2. [](#improved)
* Upgraded vendor libs for PHP 8.1 compatibility
* Upgraded to **composer v2.1.14** for PHP 8.1 compatibility

View File

@ -414,6 +414,30 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
return true;
}
public static function upstreamConfigVar(string $plugin, string $var, PageInterface $page = null, $default = null)
{
if (Utils::isAdminPlugin()) {
$page = Grav::instance()['admin']->page() ?? null;
} else {
$page = $page ?? Grav::instance()['page'] ?? null;
}
// Try to find var in the page headers
if ($page instanceof PageInterface && $page->exists()) {
// Loop over pages and look for header vars
while ($page && !$page->root()) {
$header = new Data((array)$page->header());
$value = $header->get("$plugin.$var");
if (isset($value)) {
return $value;
}
$page = $page->parent();
}
}
return Grav::instance()['config']->get("plugins.$plugin.$var", $default);
}
/**
* Simpler getter for the plugin blueprint
*