# FileManagerEvent events

> 6 FeatherPanel plugin events on FileManagerEvent (3 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/file-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. 3 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

Import `FileManagerEvent` 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\FileManagerEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(FileManagerEvent::onFileCreated(), function ($path, $isDirectory, $createdBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:file:created');
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `FileManagerEvent::onDirectoryBrowsed()`

- Name: `featherpanel:admin:file_manager:directory:browsed`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/FileManagerEvent.php#L60)

Docblock: string path, array items.

```php
$event->on(FileManagerEvent::onDirectoryBrowsed(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:directory:browsed ' . json_encode($args));
});
```

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

## `FileManagerEvent::onFileManagerError()`

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

Docblock: string error message, array context.

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

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

## `FileManagerEvent::onFileCreated()`

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

Docblock: string path, bool is\_directory. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `path` | `$path` | not declared |
| 2 | `is_directory` | `$isDirectory` | not declared |
| 3 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

-   [`FileManagerController::createFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/FileManagerController.php#L395)[`POST /api/admin/file-manager/create`](https://featherpanel.com/docs/api/reference/admin/file-manager/#post-admin-file-manager-create)

```php
$event->on(FileManagerEvent::onFileCreated(), function ($path, $isDirectory, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:file:created');
});
```

## `FileManagerEvent::onFileDeleted()`

- Name: `featherpanel:admin:file_manager:file:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/FileManagerEvent.php#L52)

Docblock: string path, bool was\_directory. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `path` | `$path` | not declared |
| 2 | `was_directory` | `$wasDirectory` | `bool` |
| 3 | `deleted_by` | `$deletedBy` | not declared |

When it fires (1 site)

-   [`FileManagerController::deleteFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/FileManagerController.php#L484)[`POST /api/admin/file-manager/delete`](https://featherpanel.com/docs/api/reference/admin/file-manager/#post-admin-file-manager-delete)

```php
$event->on(FileManagerEvent::onFileDeleted(), function ($path, $wasDirectory, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:file:deleted ' . json_encode(['was_directory' => $wasDirectory]));
});
```

## `FileManagerEvent::onFileRead()`

- Name: `featherpanel:admin:file_manager:file:read`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/FileManagerEvent.php#L28)

Docblock: string path, array file data.

```php
$event->on(FileManagerEvent::onFileRead(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:file:read ' . json_encode($args));
});
```

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

## `FileManagerEvent::onFileSaved()`

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

Docblock: string path, int size. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `path` | `$path` | not declared |
| 2 | `size` | `$size` | not declared |
| 3 | `saved_by` | `$savedBy` | not declared |

When it fires (1 site)

-   [`FileManagerController::saveFile`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/FileManagerController.php#L313)[`POST /api/admin/file-manager/save`](https://featherpanel.com/docs/api/reference/admin/file-manager/#post-admin-file-manager-save)

```php
$event->on(FileManagerEvent::onFileSaved(), function ($path, $size, $savedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:file_manager:file:saved');
});
```
