User Docs Developer Docs | |

PluginManager

AppServicesPluginManager — singleton accessed via PluginManager::instance(). Manages the full plugin lifecycle: discovery, activation, deactivation, and runtime integration (routes, admin menus).

Getting the Instance

use AppServicesPluginManager;

$pm = PluginManager::instance();

Methods

boot(): void

Called at pre_system by the CMS bootstrap. Loads all active plugins (status = 'active') by requiring their route files and calling their Plugin::boot() methods if defined. This wires plugins into the CI4 request lifecycle before the router runs.

discover(): void

Scans the plugins/ directory for plugin_info.json manifests. Performs namespace validation, vetting check (via VettingService), and inserts or updates records in the plugins table. Does not activate discovered plugins.

activate(string $folder, bool $force = false): string

Attempts to activate a plugin. Returns a status string:

Return valueMeaning
'activated'Plugin successfully activated
'not_found'Directory or manifest not found
'already_active'Plugin is already active
'requires_confirmation'Plugin is not marketplace-approved; use $force = true to override
'migration_failed'Database migration threw an exception
'install_failed'Installer::install() returned false
'invalid_license'Plugin requires a license key that is not present or not validated
$result = PluginManager::instance()->activate('PvDocs');

match ($result) {
    'activated'             => redirect()->to('admin/plugins')->with('success', 'Plugin activated'),
    'requires_confirmation' => redirect()->back()->with('warning', 'Plugin not marketplace-approved'),
    default                  => redirect()->back()->with('error', $result),
};

deactivate(string $folder): bool

Deactivates a plugin: calls Installer::uninstall() if the class exists, sets plugin status to 'inactive' in the DB. Returns true on success.

PluginManager::instance()->deactivate('PvDocs');

getMenuItems(): array

Returns the combined admin menu items contributed by all active plugins. Each item is an array with keys: label, url, icon, permission. Called by the admin layout to build the sidebar navigation.

getPublicRoutes(): array

Returns public route definitions contributed by all active plugins. Each entry is a [$method, $route, $handler] tuple. Called by app/Config/Routes.php.

getRouteFiles(): array

Returns file paths to each active plugin's Config/Routes.php. Included by the main route config for full route group support.