mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
new Plugin::upstreamConfigVar
This commit is contained in:
parent
5bec5db5e1
commit
8343cfb278
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user