downgrade to kirby v3
This commit is contained in:
@@ -3,14 +3,13 @@
|
||||
namespace Kirby\Cms;
|
||||
|
||||
use Closure;
|
||||
use Kirby\Content\Field;
|
||||
use Kirby\Exception\DuplicateException;
|
||||
use Kirby\Filesystem\Asset;
|
||||
use Kirby\Filesystem\Dir;
|
||||
use Kirby\Filesystem\F;
|
||||
use Kirby\Filesystem\Mime;
|
||||
use Kirby\Form\Field as FormField;
|
||||
use Kirby\Image\Image;
|
||||
use Kirby\Panel\Panel;
|
||||
use Kirby\Text\KirbyTag;
|
||||
use Kirby\Toolkit\A;
|
||||
use Kirby\Toolkit\Collection as ToolkitCollection;
|
||||
@@ -29,20 +28,23 @@ trait AppPlugins
|
||||
{
|
||||
/**
|
||||
* A list of all registered plugins
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static array $plugins = [];
|
||||
protected static $plugins = [];
|
||||
|
||||
/**
|
||||
* The extension registry
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected array $extensions = [
|
||||
protected $extensions = [
|
||||
// load options first to make them available for the rest
|
||||
'options' => [],
|
||||
|
||||
// other plugin types
|
||||
'api' => [],
|
||||
'areas' => [],
|
||||
'assetMethods' => [],
|
||||
'authChallenges' => [],
|
||||
'blockMethods' => [],
|
||||
'blockModels' => [],
|
||||
@@ -50,7 +52,6 @@ trait AppPlugins
|
||||
'blueprints' => [],
|
||||
'cacheTypes' => [],
|
||||
'collections' => [],
|
||||
'commands' => [],
|
||||
'components' => [],
|
||||
'controllers' => [],
|
||||
'collectionFilters' => [],
|
||||
@@ -73,8 +74,6 @@ trait AppPlugins
|
||||
'sections' => [],
|
||||
'siteMethods' => [],
|
||||
'snippets' => [],
|
||||
'structureMethods' => [],
|
||||
'structureObjectMethods' => [],
|
||||
'tags' => [],
|
||||
'templates' => [],
|
||||
'thirdParty' => [],
|
||||
@@ -88,19 +87,21 @@ trait AppPlugins
|
||||
/**
|
||||
* Flag when plugins have been loaded
|
||||
* to not load them again
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $pluginsAreLoaded = false;
|
||||
protected $pluginsAreLoaded = false;
|
||||
|
||||
/**
|
||||
* Register all given extensions
|
||||
*
|
||||
* @internal
|
||||
* @param array $extensions
|
||||
* @param \Kirby\Cms\Plugin $plugin|null The plugin which defined those extensions
|
||||
* @return array
|
||||
*/
|
||||
public function extend(
|
||||
array $extensions,
|
||||
Plugin $plugin = null
|
||||
): array {
|
||||
public function extend(array $extensions, Plugin $plugin = null): array
|
||||
{
|
||||
foreach ($this->extensions as $type => $registered) {
|
||||
if (isset($extensions[$type]) === true) {
|
||||
$this->{'extend' . $type}($extensions[$type], $plugin);
|
||||
@@ -112,43 +113,47 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers API extensions
|
||||
*
|
||||
* @param array|bool $api
|
||||
* @return array
|
||||
*/
|
||||
protected function extendApi(array|bool $api): array
|
||||
protected function extendApi($api): array
|
||||
{
|
||||
if (is_array($api) === true) {
|
||||
if (($api['routes'] ?? []) instanceof Closure) {
|
||||
if (is_a($api['routes'] ?? [], 'Closure') === true) {
|
||||
$api['routes'] = $api['routes']($this);
|
||||
}
|
||||
|
||||
return $this->extensions['api'] = A::merge($this->extensions['api'], $api, A::MERGE_APPEND);
|
||||
} else {
|
||||
return $this->extensions['api'];
|
||||
}
|
||||
|
||||
return $this->extensions['api'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional custom Panel areas
|
||||
*
|
||||
* @param array $areas
|
||||
* @return array
|
||||
*/
|
||||
protected function extendAreas(array $areas): array
|
||||
{
|
||||
foreach ($areas as $id => $area) {
|
||||
$this->extensions['areas'][$id] ??= [];
|
||||
if (isset($this->extensions['areas'][$id]) === false) {
|
||||
$this->extensions['areas'][$id] = [];
|
||||
}
|
||||
|
||||
$this->extensions['areas'][$id][] = $area;
|
||||
}
|
||||
|
||||
return $this->extensions['areas'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional asset methods
|
||||
*/
|
||||
protected function extendAssetMethods(array $methods): array
|
||||
{
|
||||
return $this->extensions['assetMethods'] = Asset::$methods = array_merge(Asset::$methods, $methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional authentication challenges
|
||||
*
|
||||
* @param array $challenges
|
||||
* @return array
|
||||
*/
|
||||
protected function extendAuthChallenges(array $challenges): array
|
||||
{
|
||||
@@ -157,6 +162,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional block methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendBlockMethods(array $methods): array
|
||||
{
|
||||
@@ -165,6 +173,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional block models
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
protected function extendBlockModels(array $models): array
|
||||
{
|
||||
@@ -173,6 +184,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional blocks methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendBlocksMethods(array $methods): array
|
||||
{
|
||||
@@ -181,6 +195,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional blueprints
|
||||
*
|
||||
* @param array $blueprints
|
||||
* @return array
|
||||
*/
|
||||
protected function extendBlueprints(array $blueprints): array
|
||||
{
|
||||
@@ -189,22 +206,20 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional cache types
|
||||
*
|
||||
* @param array $cacheTypes
|
||||
* @return array
|
||||
*/
|
||||
protected function extendCacheTypes(array $cacheTypes): array
|
||||
{
|
||||
return $this->extensions['cacheTypes'] = array_merge($this->extensions['cacheTypes'], $cacheTypes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional CLI commands
|
||||
*/
|
||||
protected function extendCommands(array $commands): array
|
||||
{
|
||||
return $this->extensions['commands'] = array_merge($this->extensions['commands'], $commands);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional collection filters
|
||||
*
|
||||
* @param array $filters
|
||||
* @return array
|
||||
*/
|
||||
protected function extendCollectionFilters(array $filters): array
|
||||
{
|
||||
@@ -213,6 +228,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional collection methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendCollectionMethods(array $methods): array
|
||||
{
|
||||
@@ -221,6 +239,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional collections
|
||||
*
|
||||
* @param array $collections
|
||||
* @return array
|
||||
*/
|
||||
protected function extendCollections(array $collections): array
|
||||
{
|
||||
@@ -229,6 +250,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers core components
|
||||
*
|
||||
* @param array $components
|
||||
* @return array
|
||||
*/
|
||||
protected function extendComponents(array $components): array
|
||||
{
|
||||
@@ -237,6 +261,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional controllers
|
||||
*
|
||||
* @param array $controllers
|
||||
* @return array
|
||||
*/
|
||||
protected function extendControllers(array $controllers): array
|
||||
{
|
||||
@@ -245,6 +272,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional file methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendFileMethods(array $methods): array
|
||||
{
|
||||
@@ -253,6 +283,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional custom file types and mimes
|
||||
*
|
||||
* @param array $fileTypes
|
||||
* @return array
|
||||
*/
|
||||
protected function extendFileTypes(array $fileTypes): array
|
||||
{
|
||||
@@ -303,6 +336,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional files methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendFilesMethods(array $methods): array
|
||||
{
|
||||
@@ -311,6 +347,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional field methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendFieldMethods(array $methods): array
|
||||
{
|
||||
@@ -319,6 +358,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers Panel fields
|
||||
*
|
||||
* @param array $fields
|
||||
* @return array
|
||||
*/
|
||||
protected function extendFields(array $fields): array
|
||||
{
|
||||
@@ -327,11 +369,16 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers hooks
|
||||
*
|
||||
* @param array $hooks
|
||||
* @return array
|
||||
*/
|
||||
protected function extendHooks(array $hooks): array
|
||||
{
|
||||
foreach ($hooks as $name => $callbacks) {
|
||||
$this->extensions['hooks'][$name] ??= [];
|
||||
if (isset($this->extensions['hooks'][$name]) === false) {
|
||||
$this->extensions['hooks'][$name] = [];
|
||||
}
|
||||
|
||||
if (is_array($callbacks) === false) {
|
||||
$callbacks = [$callbacks];
|
||||
@@ -347,14 +394,20 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers markdown component
|
||||
*
|
||||
* @param Closure $markdown
|
||||
* @return Closure
|
||||
*/
|
||||
protected function extendMarkdown(Closure $markdown): Closure
|
||||
protected function extendMarkdown(Closure $markdown)
|
||||
{
|
||||
return $this->extensions['markdown'] = $markdown;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional layout methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendLayoutMethods(array $methods): array
|
||||
{
|
||||
@@ -363,6 +416,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional layout column methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendLayoutColumnMethods(array $methods): array
|
||||
{
|
||||
@@ -371,6 +427,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional layouts methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendLayoutsMethods(array $methods): array
|
||||
{
|
||||
@@ -379,11 +438,13 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional options
|
||||
*
|
||||
* @param array $options
|
||||
* @param \Kirby\Cms\Plugin|null $plugin
|
||||
* @return array
|
||||
*/
|
||||
protected function extendOptions(
|
||||
array $options,
|
||||
Plugin $plugin = null
|
||||
): array {
|
||||
protected function extendOptions(array $options, Plugin $plugin = null): array
|
||||
{
|
||||
if ($plugin !== null) {
|
||||
$options = [$plugin->prefix() => $options];
|
||||
}
|
||||
@@ -393,6 +454,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional page methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendPageMethods(array $methods): array
|
||||
{
|
||||
@@ -401,6 +465,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional pages methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendPagesMethods(array $methods): array
|
||||
{
|
||||
@@ -409,6 +476,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional page models
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
protected function extendPageModels(array $models): array
|
||||
{
|
||||
@@ -417,6 +487,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers pages
|
||||
*
|
||||
* @param array $pages
|
||||
* @return array
|
||||
*/
|
||||
protected function extendPages(array $pages): array
|
||||
{
|
||||
@@ -425,11 +498,13 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional permissions
|
||||
*
|
||||
* @param array $permissions
|
||||
* @param \Kirby\Cms\Plugin|null $plugin
|
||||
* @return array
|
||||
*/
|
||||
protected function extendPermissions(
|
||||
array $permissions,
|
||||
Plugin $plugin = null
|
||||
): array {
|
||||
protected function extendPermissions(array $permissions, Plugin $plugin = null): array
|
||||
{
|
||||
if ($plugin !== null) {
|
||||
$permissions = [$plugin->prefix() => $permissions];
|
||||
}
|
||||
@@ -439,10 +514,13 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional routes
|
||||
*
|
||||
* @param array|\Closure $routes
|
||||
* @return array
|
||||
*/
|
||||
protected function extendRoutes(array|Closure $routes): array
|
||||
protected function extendRoutes($routes): array
|
||||
{
|
||||
if ($routes instanceof Closure) {
|
||||
if (is_a($routes, 'Closure') === true) {
|
||||
$routes = $routes($this);
|
||||
}
|
||||
|
||||
@@ -451,6 +529,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers Panel sections
|
||||
*
|
||||
* @param array $sections
|
||||
* @return array
|
||||
*/
|
||||
protected function extendSections(array $sections): array
|
||||
{
|
||||
@@ -459,6 +540,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional site methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendSiteMethods(array $methods): array
|
||||
{
|
||||
@@ -467,38 +551,31 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers SmartyPants component
|
||||
*
|
||||
* @param \Closure $smartypants
|
||||
* @return \Closure
|
||||
*/
|
||||
protected function extendSmartypants(Closure $smartypants): Closure
|
||||
protected function extendSmartypants(Closure $smartypants)
|
||||
{
|
||||
return $this->extensions['smartypants'] = $smartypants;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional snippets
|
||||
*
|
||||
* @param array $snippets
|
||||
* @return array
|
||||
*/
|
||||
protected function extendSnippets(array $snippets): array
|
||||
{
|
||||
return $this->extensions['snippets'] = array_merge($this->extensions['snippets'], $snippets);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional structure methods
|
||||
*/
|
||||
protected function extendStructureMethods(array $methods): array
|
||||
{
|
||||
return $this->extensions['structureMethods'] = Structure::$methods = array_merge(Structure::$methods, $methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional structure object methods
|
||||
*/
|
||||
protected function extendStructureObjectMethods(array $methods): array
|
||||
{
|
||||
return $this->extensions['structureObjectMethods'] = StructureObject::$methods = array_merge(StructureObject::$methods, $methods);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers additional KirbyTags
|
||||
*
|
||||
* @param array $tags
|
||||
* @return array
|
||||
*/
|
||||
protected function extendTags(array $tags): array
|
||||
{
|
||||
@@ -507,6 +584,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional templates
|
||||
*
|
||||
* @param array $templates
|
||||
* @return array
|
||||
*/
|
||||
protected function extendTemplates(array $templates): array
|
||||
{
|
||||
@@ -515,6 +595,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers translations
|
||||
*
|
||||
* @param array $translations
|
||||
* @return array
|
||||
*/
|
||||
protected function extendTranslations(array $translations): array
|
||||
{
|
||||
@@ -525,6 +608,9 @@ trait AppPlugins
|
||||
* Add third party extensions to the registry
|
||||
* so they can be used as plugins for plugins
|
||||
* for example.
|
||||
*
|
||||
* @param array $extensions
|
||||
* @return array
|
||||
*/
|
||||
protected function extendThirdParty(array $extensions): array
|
||||
{
|
||||
@@ -533,6 +619,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional user methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendUserMethods(array $methods): array
|
||||
{
|
||||
@@ -541,6 +630,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional user models
|
||||
*
|
||||
* @param array $models
|
||||
* @return array
|
||||
*/
|
||||
protected function extendUserModels(array $models): array
|
||||
{
|
||||
@@ -549,6 +641,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional users methods
|
||||
*
|
||||
* @param array $methods
|
||||
* @return array
|
||||
*/
|
||||
protected function extendUsersMethods(array $methods): array
|
||||
{
|
||||
@@ -557,6 +652,9 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Registers additional custom validators
|
||||
*
|
||||
* @param array $validators
|
||||
* @return array
|
||||
*/
|
||||
protected function extendValidators(array $validators): array
|
||||
{
|
||||
@@ -569,12 +667,11 @@ trait AppPlugins
|
||||
* @internal
|
||||
* @param string $type i.e. `'hooks'`
|
||||
* @param string $name i.e. `'page.delete:before'`
|
||||
* @param mixed $fallback
|
||||
* @return mixed
|
||||
*/
|
||||
public function extension(
|
||||
string $type,
|
||||
string $name,
|
||||
mixed $fallback = null
|
||||
): mixed {
|
||||
public function extension(string $type, string $name, $fallback = null)
|
||||
{
|
||||
return $this->extensions($type)[$name] ?? $fallback;
|
||||
}
|
||||
|
||||
@@ -582,8 +679,10 @@ trait AppPlugins
|
||||
* Returns the extensions registry
|
||||
*
|
||||
* @internal
|
||||
* @param string|null $type
|
||||
* @return array
|
||||
*/
|
||||
public function extensions(string $type = null): array
|
||||
public function extensions(string $type = null)
|
||||
{
|
||||
if ($type === null) {
|
||||
return $this->extensions;
|
||||
@@ -597,7 +696,7 @@ trait AppPlugins
|
||||
* This is only used for models for now, but
|
||||
* could be extended later
|
||||
*/
|
||||
protected function extensionsFromFolders(): void
|
||||
protected function extensionsFromFolders()
|
||||
{
|
||||
$models = [];
|
||||
|
||||
@@ -606,7 +705,7 @@ trait AppPlugins
|
||||
$class = str_replace(['.', '-', '_'], '', $name) . 'Page';
|
||||
|
||||
// load the model class
|
||||
F::loadOnce($model, allowOutput: false);
|
||||
F::loadOnce($model);
|
||||
|
||||
if (class_exists($class) === true) {
|
||||
$models[$name] = $class;
|
||||
@@ -620,8 +719,10 @@ trait AppPlugins
|
||||
* Register extensions that could be located in
|
||||
* the options array. I.e. hooks and routes can be
|
||||
* setup from the config.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function extensionsFromOptions(): void
|
||||
protected function extensionsFromOptions()
|
||||
{
|
||||
// register routes and hooks from options
|
||||
$this->extend([
|
||||
@@ -633,8 +734,10 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Apply all plugin extensions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function extensionsFromPlugins(): void
|
||||
protected function extensionsFromPlugins()
|
||||
{
|
||||
// register all their extensions
|
||||
foreach ($this->plugins() as $plugin) {
|
||||
@@ -648,22 +751,22 @@ trait AppPlugins
|
||||
|
||||
/**
|
||||
* Apply all passed extensions
|
||||
*
|
||||
* @param array $props
|
||||
* @return void
|
||||
*/
|
||||
protected function extensionsFromProps(array $props): void
|
||||
protected function extensionsFromProps(array $props)
|
||||
{
|
||||
$this->extend($props);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply all default extensions
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function extensionsFromSystem(): void
|
||||
protected function extensionsFromSystem()
|
||||
{
|
||||
// Always start with fresh fields and sections
|
||||
// from the core and add plugins on top of that
|
||||
FormField::$types = [];
|
||||
Section::$types = [];
|
||||
|
||||
// mixins
|
||||
FormField::$mixins = $this->core->fieldMixins();
|
||||
Section::$mixins = $this->core->sectionMixins();
|
||||
@@ -679,8 +782,8 @@ trait AppPlugins
|
||||
$this->extendCacheTypes($this->core->cacheTypes());
|
||||
$this->extendComponents($this->core->components());
|
||||
$this->extendBlueprints($this->core->blueprints());
|
||||
$this->extendFieldMethods($this->core->fieldMethods());
|
||||
$this->extendFields($this->core->fields());
|
||||
$this->extendFieldMethods($this->core->fieldMethods());
|
||||
$this->extendSections($this->core->sections());
|
||||
$this->extendSnippets($this->core->snippets());
|
||||
$this->extendTags($this->core->kirbyTags());
|
||||
@@ -690,6 +793,9 @@ trait AppPlugins
|
||||
/**
|
||||
* Checks if a native component was extended
|
||||
* @since 3.7.0
|
||||
*
|
||||
* @param string $component
|
||||
* @return bool
|
||||
*/
|
||||
public function isNativeComponent(string $component): bool
|
||||
{
|
||||
@@ -699,8 +805,11 @@ trait AppPlugins
|
||||
/**
|
||||
* Returns the native implementation
|
||||
* of a core component
|
||||
*
|
||||
* @param string $component
|
||||
* @return \Closure|false
|
||||
*/
|
||||
public function nativeComponent(string $component): Closure|false
|
||||
public function nativeComponent(string $component)
|
||||
{
|
||||
return $this->core->components()[$component] ?? false;
|
||||
}
|
||||
@@ -708,30 +817,22 @@ trait AppPlugins
|
||||
/**
|
||||
* Kirby plugin factory and getter
|
||||
*
|
||||
* @param string $name
|
||||
* @param array|null $extends If null is passed it will be used as getter. Otherwise as factory.
|
||||
* @return \Kirby\Cms\Plugin|null
|
||||
* @throws \Kirby\Exception\DuplicateException
|
||||
*/
|
||||
public static function plugin(
|
||||
string $name,
|
||||
array $extends = null,
|
||||
array $info = [],
|
||||
string|null $root = null,
|
||||
string|null $version = null
|
||||
): Plugin|null {
|
||||
public static function plugin(string $name, array $extends = null)
|
||||
{
|
||||
if ($extends === null) {
|
||||
return static::$plugins[$name] ?? null;
|
||||
}
|
||||
|
||||
$plugin = new Plugin(
|
||||
name: $name,
|
||||
extends: $extends,
|
||||
info: $info,
|
||||
// TODO: Remove fallback to $extends in v7
|
||||
root: $root ?? $extends['root'] ?? dirname(debug_backtrace()[0]['file']),
|
||||
version: $version
|
||||
);
|
||||
// get the correct root for the plugin
|
||||
$extends['root'] = $extends['root'] ?? dirname(debug_backtrace()[0]['file']);
|
||||
|
||||
$name = $plugin->name();
|
||||
$plugin = new Plugin($name, $extends);
|
||||
$name = $plugin->name();
|
||||
|
||||
if (isset(static::$plugins[$name]) === true) {
|
||||
throw new DuplicateException('The plugin "' . $name . '" has already been registered');
|
||||
@@ -746,6 +847,7 @@ trait AppPlugins
|
||||
*
|
||||
* @internal
|
||||
* @param array|null $plugins Can be used to overwrite the plugins registry
|
||||
* @return array
|
||||
*/
|
||||
public function plugins(array $plugins = null): array
|
||||
{
|
||||
@@ -794,17 +896,13 @@ trait AppPlugins
|
||||
$styles = $dir . '/index.css';
|
||||
|
||||
if (is_file($entry) === true) {
|
||||
F::loadOnce($entry, allowOutput: false);
|
||||
F::loadOnce($entry);
|
||||
} elseif (is_file($script) === true || is_file($styles) === true) {
|
||||
// if no PHP file is present but an index.js or index.css,
|
||||
// register as anonymous plugin (without actual extensions)
|
||||
// to be picked up by the Panel\Document class when
|
||||
// rendering the Panel view
|
||||
static::plugin(
|
||||
name: 'plugins/' . $dirname,
|
||||
extends: [],
|
||||
root: $dir
|
||||
);
|
||||
static::plugin('plugins/' . $dirname, ['root' => $dir]);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user