# PluginManagerEvent events

> 5 FeatherPanel plugin events on PluginManagerEvent (4 emitted by the core): the event names, the arguments each listener gets, where they fire and a PHP listener for each.

Source: https://featherpanel.com/docs/plugins/events/plugin-manager/

Part of the [plugin events reference](https://featherpanel.com/docs/plugins/events/). Listeners get the payload values as positional arguments in the order shown, cannot cancel the action, and must catch their own exceptions. 1 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `PluginManagerEvent` in your entry class and register listeners in `processEvents()`:

```php
<?php

namespace App\Addons\myplugin;

use App\App;
use App\Plugins\AppPlugin;
use App\Plugins\PluginEvents;
use App\Plugins\Events\Events\PluginManagerEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(PluginManagerEvent::onPluginFileCreated(), function ($identifier, $fileType, $fileData, $createdBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:file:created ' . json_encode(['identifier' => $identifier, 'file_type' => $fileType, 'file_data' => $fileData]));
        });
    }

    public static function pluginInstall(): void
    {
    }

    public static function pluginUninstall(): void
    {
    }
}
```

## `PluginManagerEvent::onPluginManagerError()`

- Name: `featherpanel:admin:plugin_manager:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginManagerEvent.php#L61)

Docblock: string error message, array context.

```php
$event->on(PluginManagerEvent::onPluginManagerError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:error ' . json_encode($args));
});
```

No code emits this event yet, so the arguments are unknown. The listener accepts any.

## `PluginManagerEvent::onPluginFileCreated()`

- Name: `featherpanel:admin:plugin_manager:file:created`
- emitted at 3 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginManagerEvent.php#L52)

Docblock: string identifier, string file type, array file data. (the emitter passes 4 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | `string` |
| 2 | `file_type` | `$fileType` | `string` |
| 3 | `file_data` | `$fileData` | `array` |
| 4 | `created_by` | `$createdBy` | not declared |

When it fires (3 sites)

-   [`PluginManagerController::createPluginFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L913)[`POST /api/admin/plugin-tools/create-file`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#post-admin-plugin-tools-create-file)
-   [`PluginManagerController::updatePluginWidgets`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L1200)
-   [`PluginManagerController::deletePluginWidget`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L1323)

```php
$event->on(PluginManagerEvent::onPluginFileCreated(), function ($identifier, $fileType, $fileData, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:file:created ' . json_encode(['identifier' => $identifier, 'file_type' => $fileType, 'file_data' => $fileData]));
});
```

## `PluginManagerEvent::onPluginCreated()`

- Name: `featherpanel:admin:plugin_manager:plugin:created`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginManagerEvent.php#L28)

Docblock: string identifier, array plugin data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | not declared |
| 2 | `plugin_data` | `$pluginData` | not declared |
| 3 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

-   [`PluginManagerController::createPlugin`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L415)[`POST /api/admin/plugin-manager`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#post-admin-plugin-manager)

```php
$event->on(PluginManagerEvent::onPluginCreated(), function ($identifier, $pluginData, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:plugin:created');
});
```

## `PluginManagerEvent::onPluginUpdated()`

- Name: `featherpanel:admin:plugin_manager:plugin:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginManagerEvent.php#L36)

Docblock: string identifier, array updated data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | not declared |
| 2 | `updated_data` | `$updatedData` | not declared |
| 3 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

-   [`PluginManagerController::updatePlugin`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L552)[`PUT /api/admin/plugin-manager/{identifier}`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#put-admin-plugin-manager-identifier), [`PATCH /api/admin/plugin-manager/{identifier}`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#patch-admin-plugin-manager-identifier)

```php
$event->on(PluginManagerEvent::onPluginUpdated(), function ($identifier, $updatedData, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:plugin:updated');
});
```

## `PluginManagerEvent::onPluginSettingsUpdated()`

- Name: `featherpanel:admin:plugin_manager:settings:updated`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/PluginManagerEvent.php#L44)

Docblock: string identifier, array settings data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `identifier` | `$identifier` | not declared |
| 2 | `settings` | `$settings` | not declared |
| 3 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

-   [`PluginManagerController::updatePluginSettings`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PluginManagerController.php#L703)[`PUT /api/admin/plugin-manager/{identifier}/settings`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#put-admin-plugin-manager-identifier-settings), [`PATCH /api/admin/plugin-manager/{identifier}/settings`](https://featherpanel.com/docs/api/reference/admin/plugin-manager/#patch-admin-plugin-manager-identifier-settings)

```php
$event->on(PluginManagerEvent::onPluginSettingsUpdated(), function ($identifier, $settings, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:plugin_manager:settings:updated');
});
```
