This commit is contained in:
2022-03-14 12:15:17 +01:00
parent f6e7464f8c
commit 22adba5d54
473 changed files with 4722 additions and 1766 deletions
+30 -2
View File
@@ -3,7 +3,7 @@
/**
* @package Grav\Common
*
* @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
* @copyright Copyright (c) 2015 - 2022 Trilby Media, LLC. All rights reserved.
* @license MIT License; see LICENSE file for details.
*/
@@ -118,7 +118,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
*/
public function config()
{
return null !== $this->config ? $this->config["plugins.{$this->name}"] : [];
return $this->config["plugins.{$this->name}"] ?? [];
}
/**
@@ -227,6 +227,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset An offset to check for.
* @return bool Returns TRUE on success or FALSE on failure.
*/
#[\ReturnTypeWillChange]
public function offsetExists($offset)
{
if ($offset === 'title') {
@@ -244,6 +245,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset The offset to retrieve.
* @return mixed Can return all value types.
*/
#[\ReturnTypeWillChange]
public function offsetGet($offset)
{
if ($offset === 'title') {
@@ -262,6 +264,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param mixed $value The value to set.
* @throws LogicException
*/
#[\ReturnTypeWillChange]
public function offsetSet($offset, $value)
{
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
@@ -273,6 +276,7 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
* @param string $offset The offset to unset.
* @throws LogicException
*/
#[\ReturnTypeWillChange]
public function offsetUnset($offset)
{
throw new LogicException(__CLASS__ . ' blueprints cannot be modified.');
@@ -410,6 +414,30 @@ class Plugin implements EventSubscriberInterface, ArrayAccess
return true;
}
public static function inheritedConfigOption(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
*