# ServerSubuserEvent events

> 4 FeatherPanel plugin events on ServerSubuserEvent (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/server-subuser/

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 `ServerSubuserEvent` 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\ServerSubuserEvent;

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(ServerSubuserEvent::onServerSubuserUpdated(), function ($userUuid, $serverUuid, $subuserId): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:subuser:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'subuser_id' => $subuserId]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `ServerSubuserEvent::onServerSubuserCreated()`

- Name: `featherpanel:user:server:subuser:created`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerSubuserEvent.php#L28)

Docblock: string server uuid, array subuser data. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerSubuserCreated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `subuser_id` | `$subuserId` | not declared |

When it fires (2 sites)

-   [`SubuserController::createSubuser`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubuserController.php#L427)[`POST /api/user/servers/{uuidShort}/subusers`](https://featherpanel.com/docs/api/reference/user/server/subusers/#post-user-servers-uuidShort-subusers)
-   [`SubuserInviteController::accept`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubuserInviteController.php#L162)

```php
$event->on(ServerSubuserEvent::onServerSubuserCreated(), function ($userUuid, $serverUuid, $subuserId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:subuser:created');
});
```

## `ServerSubuserEvent::onServerSubuserDeleted()`

- Name: `featherpanel:user:server:subuser:deleted`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerSubuserEvent.php#L44)

Docblock: string server uuid, int subuser id. (the emitter passes 3 values, see the table)

Same event name as `ServerEvent::onServerSubuserDeleted()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | not declared |
| 2 | `server_uuid` | `$serverUuid` | not declared |
| 3 | `subuser_id` | `$subuserId` | `int` |

When it fires (1 site)

-   [`SubuserController::deleteSubuser`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubuserController.php#L731)[`DELETE /api/user/servers/{uuidShort}/subusers/{subuserId}`](https://featherpanel.com/docs/api/reference/user/server/subusers/#delete-user-servers-uuidShort-subusers-subuserId)

```php
$event->on(ServerSubuserEvent::onServerSubuserDeleted(), function ($userUuid, $serverUuid, $subuserId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:subuser:deleted ' . json_encode(['subuser_id' => $subuserId]));
});
```

## `ServerSubuserEvent::onServerSubuserError()`

- Name: `featherpanel:user:server:subuser:error`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/ServerSubuserEvent.php#L53)

Docblock: string error message, array context.

```php
$event->on(ServerSubuserEvent::onServerSubuserError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:subuser:error ' . json_encode($args));
});
```

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

## `ServerSubuserEvent::onServerSubuserUpdated()`

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

Docblock: string server uuid, int subuser id, array updated data.

Same event name as `ServerEvent::onServerSubuserUpdated()`. A listener on either method receives the emits of both.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `user_uuid` | `$userUuid` | `string`from docblock |
| 2 | `server_uuid` | `$serverUuid` | `int`from docblock |
| 3 | `subuser_id` | `$subuserId` | `int` |

When it fires (1 site)

-   [`SubuserController::updateSubuser`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubuserController.php#L630)[`PATCH /api/user/servers/{uuidShort}/subusers/{subuserId}`](https://featherpanel.com/docs/api/reference/user/server/subusers/#patch-user-servers-uuidShort-subusers-subuserId)

```php
$event->on(ServerSubuserEvent::onServerSubuserUpdated(), function ($userUuid, $serverUuid, $subuserId): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:server:subuser:updated ' . json_encode(['user_uuid' => $userUuid, 'server_uuid' => $serverUuid, 'subuser_id' => $subuserId]));
});
```
