Improve plugin autoloading and error handling - #943
Conversation
There was a problem hiding this comment.
Pull request overview
This PR strengthens plugin management by introducing a base plugin configuration scheme, improving backend handling of plugin initialization failures, and updating the panel UI/translations to surface enablement errors more consistently.
Changes:
- Wrap plugin autoload/initialization failures in a dedicated
PluginInitializationExceptionand handle enablement failures by rolling back the enabled flag and notifying the user. - Introduce a base plugin scheme (
plugins.plugin) to guarantee anenabledfield for all plugin schemes, and ensure plugin schemes extend/receive that base. - Improve the panel toggle UX and add translated error strings for initialization errors.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| formwork/src/Plugins/Exceptions/PluginInitializationException.php | Adds a dedicated exception type for plugin init/autoload failures. |
| formwork/src/Plugins/Plugins.php | Wraps autoload/initialize errors and adjusts autoloader registration behavior. |
| formwork/src/Plugins/Plugin.php | Reserves plugin id plugin and clarifies autoload() usage as internal. |
| formwork/src/Panel/Controllers/PluginsController.php | Enforces base plugin scheme usage and rolls back enablement when initialization fails. |
| formwork/src/Schemes/Scheme.php | Adds extendsScheme() helper for scheme inheritance checks. |
| formwork/schemes/plugins/plugin.yaml | Introduces the base plugin scheme containing an (hidden) enabled field. |
| panel/src/ts/components/views/plugins.ts | Updates toggle handling to revert UI state on enable/disable errors. |
| panel/translations/en.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/de.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/el.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/es.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/fr.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/hu.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/it.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/nl.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/pl.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/pt.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/ro.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/ru.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/sv.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/tr.yaml | Adds translated “cannot enable due to initialization error” string. |
| panel/translations/uk.yaml | Adds translated “cannot enable due to initialization error” string. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
formwork/src/Panel/Controllers/PluginsController.php:79
- Only visible fields are passed to the view, so the base
enabledfield (visible: false) won’t be posted back on save.Form::processRequest()then resets missing fields to their defaults, andupdatePluginsOptions()will writeenabled: 0, potentially disabling an enabled plugin just by saving options.
return new Response($this->view('@panel.plugins.plugin', [
'title' => $plugin->manifest()->title() ?? $plugin->name(),
'plugin' => $plugin,
'fields' => $form->fields()->filter(fn($field) => $field->isVisible()),
...$this->getPreviousAndNextPlugin($plugin),
panel/src/ts/components/views/plugins.ts:33
- The callback reloads the page whenever the plugin form is unchanged, regardless of whether the request succeeded. This means enable/disable errors can get silently swallowed (no notification and no toggle rollback), which defeats the new error-handling behavior.
if (!app.forms["plugin-form"]?.hasChanged()) {
window.location.reload();
} else {
const notification = new Notification(response.message, response.status);
notification.show();
b9fd768 to
f757032
Compare
This pull request introduces several improvements to plugin management, focusing on safer plugin initialization, enhanced error handling, and better consistency for plugin configuration schemes. It adds a base plugin scheme, ensures all plugin schemes extend this base, improves feedback when enabling plugins fails, and updates the frontend to handle errors more gracefully. Additionally, new translation strings for initialization errors are added in multiple languages.
Plugin initialization and error handling:
PluginInitializationExceptionand updated thePlugins::initializemethod to catch and wrap errors during plugin autoloading and initialization, providing better error reporting and preventing plugins from being enabled if initialization fails. (formwork/src/Plugins/Exceptions/PluginInitializationException.php,formwork/src/Plugins/Plugins.php,formwork/src/Panel/Controllers/PluginsController.php) [1] [2] [3] [4]formwork/src/Panel/Controllers/PluginsController.php,panel/translations/*.yaml) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14]Plugin scheme enforcement and configuration:
formwork/schemes/plugins/plugin.yamlwith anenabledfield, and updated the backend to ensure all plugin schemes extend this base, guaranteeing the presence of theenabledfield for all plugins. (formwork/schemes/plugins/plugin.yaml,formwork/src/Panel/Controllers/PluginsController.php,formwork/src/Schemes/Scheme.php) [1] [2] [3]formwork/src/Panel/Controllers/PluginsController.php) [1] [2]Frontend improvements:
panel/src/ts/components/views/plugins.ts) [1] [2]Validation and restrictions:
pluginand improved error messages for invalid plugin ids. (formwork/src/Plugins/Plugin.php)autoloadmethod in the plugin lifecycle. (formwork/src/Plugins/Plugin.php)