mirror of
https://github.com/getgrav/grav.git
synced 2026-07-04 15:37:26 +02:00
Added Plugins::getPlugins() and Plugins::getPlugin($name) to make it easier to access plugin instances [#2277]
This commit is contained in:
@@ -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`
|
||||
|
||||
@@ -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.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user