Add VendorModuleService for Composer-based Webtrees modules#5227
Add VendorModuleService for Composer-based Webtrees modules#5227magicsunday wants to merge 3 commits into
Conversation
|
Together with Webtrees 2.2.4 or dev-main, this can currently be tested using the magicsunday/webtrees-fan-chart package, for example. To do this, the WIP branch must be checked out.
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5227 +/- ##
============================================
+ Coverage 35.49% 36.88% +1.39%
- Complexity 11211 11554 +343
============================================
Files 1166 1208 +42
Lines 48077 49796 +1719
============================================
+ Hits 17065 18369 +1304
- Misses 31012 31427 +415 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I develop modules purely for my own use. I have no need or interest in using composer. I know there are many others doing the same. For us modules_v4 is simple and works well. So how does this proposal affect us? There is no mention of users like us in this. |
|
Thanks for raising this — it’s an important point. To be clear: this proposal does not remove or break the existing What this PR does is add an additional option for distributing and installing modules via Composer, using the new
So to summarize:
The goal here is to expand possibilities without taking anything away. |
|
Hi @fisharebest, I hope you're well. I'd appreciate it if you'd take a look at this PR. If you find any issues, I'm happy to adjust or improve it. Thank you for your time and feedback! |
|
Nice work! |
|
Thanks for the kind feedback! Let me clarify: What steps are needed to publish a module?
That’s it — Composer takes care of the rest (autoloading, versioning, installation path, etc.). Does this add more dependencies for webtrees?
So in short:
|
|
As I understand it, this approach will complicate things tremendously for site admins that 'simply' want to install or try out a vendor module. Currently all that's needed is unzip the module source code into a subdirectory of With this mechanism they need to clone the webtrees git repo, edit some file, have a local PHP development environment in order to execute Thus the requirements for using such modules are raised significantly. Or am I missing something? |
|
Hi @BertKoor |
|
Thanks for pointing that out, @kiwi3685 . I thought I had read the complete discussion, but apparently I had misunderstood some nuances. You addressed concerns from the point of view of a module developer. It was mentioned that this "does not remove or break the existing Now should I understand that "composer"-ised modules can be installed the old way as well? In my experience more options leads to confusion, especially on unknown territory. And I hope that n>1 for this feature, but I have my doubts. |
@fisharebest |
|
Instead of modifying webtrees to search for modules in a new location ( From reading the composer documentation, I think that the following steps are required
{
"extra": {
"installer-paths": {
"modules_v4": ["type:webtrees-module"]
}
}
}If you want to script this, you can use this command line to make the edit. jq '.extra["installer-paths"]["modules_v4"] = ["type:webtrees-module"]' composer.json > tmp && mv tmp composer.json
On the webtrees system, you should be able to run Does this work? |
|
/edit The installation path might need to be |
|
I was wondering if |
|
I have created a minimal webtrees module installer. It's just a few lines of code. I see that @magicsunday has created a much more comprehensive installer. I didn't look to see what additional features it provides. But a module should be able to use any installer, not just one of these two. Now, if a module specifies its type ( e.g. this is an example module that you can install now.
|
8064170 to
bde39f5
Compare
|
Hi @fisharebest, thank you so much for looking into this and creating the minimal installer – I really appreciate your effort! I'd like to share my thoughts on why I believe the VendorModuleService approach offers significant technical advantages over the installer-based approach. To clarify, this isn't a core change, but rather a core extension. The existing code remains unchanged; only an additional path for module discovery is added. A real-world use case: Development workflow. Developing and maintaining multiple interdependent modules using the modules_v4 approach is cumbersome in practice. My modules (fan-chart, pedigree-chart, descendants-chart) all depend on a common base package (webtrees-module-base). With modules_v4, any change to the base package requires manually copying or creating symbolic links – and synchronizing all modules is prone to errors. With the VendorModuleService, Composer manages the entire dependency graph automatically. A You can see this in action in my project https://github.com/magicsunday/webtrees-docker. There, the entire Webtrees stack (including custom modules) is managed through a single Established pattern in the PHP ecosystem: This approach follows the pattern used by major frameworks. For example, TYPO3 uses the package type
With the VendorModuleService, this workaround is unnecessary, as the Composer autoloader already knows the module's namespace.
I am happy to adapt the implementation if you have concerns about specific code sections. However, I am convinced that keeping the modules in |
9e17ce4 to
15d4318
Compare
|
Hi @fisharebest, following up here — I think the discussion has surfaced both approaches clearly, so I'd rather not restate the technical arguments again. Where we are, briefly:
What would really help is a direction decision, so the PR doesn't sit open indefinitely:
Either outcome is fine — I'd just like to know which direction to invest in. Thanks for your time on this. |
… theme support Brings the downstream patch in line with the corrected upstream PR (fisharebest/webtrees#5227): - Load only packages that sit at their standard <vendor>/<package> path. A module relocated into modules_v4/ (installer-plugin) or a nested-vendor self-entry (a module bundling its own vendor/ that registers itself as a Composer package) reports a different install path and is already loaded by ModuleService::customModules(); loading it here too included its module.php twice and fataled with "Cannot redeclare class". The vendor directory is resolved via the registered class loaders (drupal-finder approach), as Composer exposes no accessor (composer/composer#2904). - Also discover webtrees-theme packages, not just webtrees-module, accepting ModuleThemeInterface alongside ModuleCustomInterface. Keeps the downstream-only traits (final class, error_log instead of FlashMessages for the bootstrap-context discovery, explode-based name derivation). Verified with git apply --check + php -l against webtrees 2.2.6; the build sentinel (merge($this->vendorModules())) and the composer-patches lockstep are unaffected.
…upport VendorModuleService discovered packages via InstalledVersions, which aggregates the bundled installed.php of every registered class loader. A module installed under modules_v4/ (moved there by the installer-plugin, or bundling its own vendor/ and registering itself as a Composer package) therefore showed up here as well as in ModuleService::customModules(), so its module.php was included twice. Modules that pull their class file with plain require (not require_once) then fatal with "Cannot redeclare class". Only load a package that sits at its standard Composer location (<vendor>/<package>); a relocated or nested-vendor self-entry reports a different install path and is left to customModules(). The vendor directory is resolved via the registered class loaders (the drupal-finder approach), as Composer exposes no dedicated accessor (composer/composer#2904). Also collect webtrees-theme packages, not just webtrees-module, mirroring the webtrees-module-installer-plugin, and accept ModuleThemeInterface alongside ModuleCustomInterface.
Add
VendorModuleServicefor Composer-based Webtrees modules🚀 Feature: Vendor Module Support via Composer (
VendorModuleService)Overview
This PR introduces a new service class,
VendorModuleService, that allows Webtrees to seamlessly load modules installed via Composer.A key part of this feature is the introduction of a new Composer package type:
webtrees-module. This package type signals that a Composer package is a Webtrees extension, making it automatically discoverable and loadable by the Webtrees core.This modernizes module management and brings Webtrees closer in line with practices used by frameworks such as Symfony, Laravel, and TYPO3.
Why?
Currently, Webtrees modules are installed and managed manually in the
modules_v4directory. While functional, this approach has limitations:By enabling Composer-managed modules (via
webtrees-module), we provide:composer require vendor/package)This makes Webtrees more attractive to external developers and lowers the barrier for creating and sharing extensions.
How It Works
The
VendorModuleServiceleverages Composer’s InstalledVersions API to:webtrees-modulemodule.phpentrypointModuleServiceFlashMessagesInternally:
composer.json→"type": "webtrees-module"_mypackage_)Benefits
📦 Example
composer.jsonfor a Webtrees Module{ "name": "my-vendor/my-webtrees-module", "description": "An example Webtrees module distributed via Composer.", "type": "webtrees-module", "license": "GPL-3.0-or-later", "authors": [ { "name": "Your Name", "email": "you@example.com" } ], "require": { "php": ">=8.1", "fisharebest/webtrees": "^2.2" }, "autoload": { "psr-4": { "MyVendor\\MyWebtreesModule\\": "src/" } } }