# MountsEvent events

> 3 FeatherPanel plugin events on MountsEvent (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/mounts/

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.

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(MountsEvent::onMountDeleted(), function ($mountId, $deletedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:mounts:mount:deleted ' . json_encode(['mount_id' => $mountId, 'deleted_by' => $deletedBy]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `MountsEvent::onMountCreated()`

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

Docblock: array mount data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `mount_id` | `$mountId` | not declared |
| 2 | `mount` | `$mount` | not declared |
| 3 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

-   [`MountsController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/MountsController.php#L138) via `emitPluginEvent()`[`PUT /api/admin/mounts`](https://featherpanel.com/docs/api/reference/admin/mounts/#put-admin-mounts)

```php
$event->on(MountsEvent::onMountCreated(), function ($mountId, $mount, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:mounts:mount:created');
});
```

## `MountsEvent::onMountDeleted()`

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

Docblock: int mount id, array mount data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `mount_id` | `$mountId` | `int` |
| 2 | `deleted_by` | `$deletedBy` | `array`from docblock |

When it fires (1 site)

-   [`MountsController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/MountsController.php#L243) via `emitPluginEvent()`[`DELETE /api/admin/mounts/{id}`](https://featherpanel.com/docs/api/reference/admin/mounts/#delete-admin-mounts-id)

```php
$event->on(MountsEvent::onMountDeleted(), function ($mountId, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:mounts:mount:deleted ' . json_encode(['mount_id' => $mountId, 'deleted_by' => $deletedBy]));
});
```

## `MountsEvent::onMountUpdated()`

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

Docblock: int mount id, array mount data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `mount_id` | `$mountId` | `int` |
| 2 | `mount` | `$mount` | not declared |
| 3 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

-   [`MountsController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/MountsController.php#L215) via `emitPluginEvent()`[`PATCH /api/admin/mounts/{id}`](https://featherpanel.com/docs/api/reference/admin/mounts/#patch-admin-mounts-id)

```php
$event->on(MountsEvent::onMountUpdated(), function ($mountId, $mount, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:mounts:mount:updated ' . json_encode(['mount_id' => $mountId]));
});
```
