Added Plugins::getPlugins() and Plugins::getPlugin($name) to make it easier to access plugin instances [#2277]

This commit is contained in:
Matias Griese
2021-02-11 10:10:50 +02:00
parent 49fca0da2b
commit 129fd7fdad
2 changed files with 28 additions and 0 deletions

View File

@@ -3,6 +3,7 @@
1. [](#new)
* Added `Medium::attribute()` to pass arbitrary attributes [#3065](https://github.com/getgrav/grav/pull/3065)
* Added `Plugins::getPlugins()` and `Plugins::getPlugin($name)` to make it easier to access plugin instances [#2277](https://github.com/getgrav/grav/pull/2277)
1. [](#improved)
* Added abstract `FlexObject`, `FlexCollection` and `FlexIndex` classes to `\Grav\Common\Flex` namespace (extend those instead of Framework or Generic classes)
* Updated bundled `composer.phar` binary to latest version `2.0.9`

View File

@@ -170,6 +170,33 @@ class Plugins extends Iterator
return $array;
}
/**
* @return Plugin[] Index of all plugins by plugin name.
*/
public static function getPlugins(): array
{
$grav = Grav::instance();
$plugins = $grav['plugins'];
$list = [];
foreach ($plugins as $instance) {
$list[$instance->name] = $instance;
}
return $list;
}
/**
* @param string $name Plugin name
* @return Plugin|null Plugin object or null if plugin cannot be found.
*/
public static function getPlugin(string $name)
{
$list = static::getPlugins();
return $list[$name] ?? null;
}
/**
* Return list of all plugin data with their blueprints.
*