I want to use a plugin to keep code shared between multiple instances of a theme DRY.
So I thought it would be possible to require Kirby Plugins inside this plugin, but when doing so, they do not install into /site/plugins of Kirbys root folder, but in /site/plugins inside the plugin folder, where Kirby obviously not loads them.
I already tried specifying a custom path but without luck. But I guess I’m missing something and would be thankful for any help.
What do you mean by “they [do not] install”? What’s the installation process for the dma-ev/yogikit-plugin plugin?
From what I’ve seen, Kirby plugins which use dependencies from Packagist follow this pattern:
They have a composer.json with some required packages.
They install those dependencies with composer into a vendor folder within their own directory (e.g. at the root of a Git repository dedicated to their plugin), and commit the generated vendor/* files, including the vendor/autoload.php.
When publishing their plugin to Packagist, they exclude the vendor folder from the published package.
The result is that manual installation by downloading a zip archive from GitHub (or some other Git host), extracting the archive and placing the files manually into a project’s site/plugins folder is going to work. Users will end up with something like:
In the second case, both cool-plugin and required-kirby-plugin would be automatically loaded by Kirby, so there isn’t anything else to do.
In the first case, you may need to do some loading of your vendored dependencies:
<?php
// site/plugins/cool-plugin/index.php
if (is_file($autoloader = __DIR__ . '/vendor/autoload.php')) {
include $autoloader;
}
Of course the Kirby plugins you vendored in your own Git repository may not have any PSR-0 or PSR-4 autoloading configuration, and instead expect to be moved to site/plugins by getkirby/composer-installer, which won’t be the case here. So you may need to explicitly include them:
<?php
// site/plugins/cool-plugin/index.php
if (is_file($autoloader = __DIR__ . '/vendor/autoload.php')) {
include $autoloader;
}
if (is_file($required_plugin = __DIR__ . '/vendor/some-vendor/required-kirby-plugin/index.php')) {
include $required_plugin;
}
First of all, thank you @fvsch for taking the time to reply in such detail – I really appreciate it.
And then I have to say sorry for not making clearer what my intention (and problem) is was:
I want to use Kirbys built-in feature of overriding templates, blueprints etc. defined in a plugin by just adding the same file to respective paths in the root folder. This way I can develop code shared between sites and still easily add/override where needed.
Same with plugins: Manage all plugins shared by all sites in that plugin by adding them as composer dependencies there.
I now found my error in thinking:
I called composer installinside the plugin directory and wanted the kirby plugins to be downloaded (thats what I meant by installed) into the plugin directory in the root folder.
This put me on the right path to finding a solution:
As I want to keep my repo private (for now) it is not available on packagist, but I found this article how to require a local composer package. And by requiring the package locally the project root, composer dependencies inside the plugin are correctly downloaded into the directories they belong.
And just in case anyone is looking for a similar approach:
Even if you have a private repo, you can require it in a similar way as a local package mentioned in the link above (copied from composer docks):