Skip to content

Improve plugin autoloading and error handling - #943

Merged
giuscris merged 10 commits into
2.xfrom
feature/improved-plugins-checks
Aug 27, 2026
Merged

Improve plugin autoloading and error handling#943
giuscris merged 10 commits into
2.xfrom
feature/improved-plugins-checks

Conversation

@giuscris

Copy link
Copy Markdown
Member

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:

  • Introduced a PluginInitializationException and updated the Plugins::initialize method 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]
  • The panel now notifies the user and rolls back the enabled status if a plugin fails to initialize, with translated error messages. (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:

  • Added a base plugin scheme in formwork/schemes/plugins/plugin.yaml with an enabled field, and updated the backend to ensure all plugin schemes extend this base, guaranteeing the presence of the enabled field for all plugins. (formwork/schemes/plugins/plugin.yaml, formwork/src/Panel/Controllers/PluginsController.php, formwork/src/Schemes/Scheme.php) [1] [2] [3]
  • Improved the plugin configuration form to only show visible fields and simplified the logic for retrieving and displaying plugin scheme fields. (formwork/src/Panel/Controllers/PluginsController.php) [1] [2]

Frontend improvements:

  • Updated the plugin status toggle UI to handle enable/disable errors more gracefully by reverting the toggle and re-enabling the control if an error occurs. (panel/src/ts/components/views/plugins.ts) [1] [2]

Validation and restrictions:

  • Prevented plugins from using the reserved id plugin and improved error messages for invalid plugin ids. (formwork/src/Plugins/Plugin.php)
  • Added documentation to clarify the internal use of the autoload method in the plugin lifecycle. (formwork/src/Plugins/Plugin.php)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 PluginInitializationException and handle enablement failures by rolling back the enabled flag and notifying the user.
  • Introduce a base plugin scheme (plugins.plugin) to guarantee an enabled field 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.

Comment thread formwork/src/Plugins/Plugins.php Outdated
Comment thread formwork/src/Plugins/Plugins.php
Comment thread panel/src/ts/components/views/plugins.ts
Comment thread formwork/src/Schemes/Scheme.php Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 enabled field (visible: false) won’t be posted back on save. Form::processRequest() then resets missing fields to their defaults, and updatePluginsOptions() will write enabled: 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();

Comment thread formwork/src/Schemes/Scheme.php
@giuscris
giuscris force-pushed the feature/improved-plugins-checks branch from b9fd768 to f757032 Compare August 27, 2026 09:09
@giuscris
giuscris merged commit e74d0ce into 2.x Aug 27, 2026
2 checks passed
@giuscris
giuscris deleted the feature/improved-plugins-checks branch August 27, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants