# SubdomainsEvent events

> 10 FeatherPanel plugin events on SubdomainsEvent (9 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/subdomains/

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(SubdomainsEvent::onSubdomainDomainNotFound(), function ($domainUuid, $errorMessage): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:not:found ' . json_encode(['domain_uuid' => $domainUuid, 'error_message' => $errorMessage]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `SubdomainsEvent::onSubdomainDomainCreated()`

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

Docblock: array domain data. (the emitter passes 2 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domain_data` | `$domainData` | not declared |
| 2 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

-   [`SubdomainsController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L296)[`PUT /api/admin/subdomains`](https://featherpanel.com/docs/api/reference/admin/subdomains/#put-admin-subdomains)

```php
$event->on(SubdomainsEvent::onSubdomainDomainCreated(), function ($domainData, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:created');
});
```

## `SubdomainsEvent::onSubdomainDomainDeleted()`

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

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domain_uuid` | `$domainUuid` | `string` |
| 2 | `domain_data` | `$domainData` | not declared |
| 3 | `deleted_by` | `$deletedBy` | not declared |

When it fires (1 site)

-   [`SubdomainsController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L417)[`DELETE /api/admin/subdomains/{uuid}`](https://featherpanel.com/docs/api/reference/admin/subdomains/#delete-admin-subdomains-uuid)

```php
$event->on(SubdomainsEvent::onSubdomainDomainDeleted(), function ($domainUuid, $domainData, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:deleted ' . json_encode(['domain_uuid' => $domainUuid]));
});
```

## `SubdomainsEvent::onSubdomainDomainNotFound()`

- Name: `featherpanel:admin:subdomains:domain:not:found`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SubdomainsEvent.php#L102)

Docblock: string domain uuid, string error message.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domain_uuid` | `$domainUuid` | `string` |
| 2 | `error_message` | `$errorMessage` | `string` |

When it fires (1 site)

-   [`SubdomainsController::listSubdomains`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L498)[`GET /api/admin/subdomains/{uuid}/subdomains`](https://featherpanel.com/docs/api/reference/admin/subdomains/#get-admin-subdomains-uuid-subdomains)

```php
$event->on(SubdomainsEvent::onSubdomainDomainNotFound(), function ($domainUuid, $errorMessage): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:not:found ' . json_encode(['domain_uuid' => $domainUuid, 'error_message' => $errorMessage]));
});
```

## `SubdomainsEvent::onSubdomainDomainRetrieved()`

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

Docblock: string domain uuid, array domain data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domain_uuid` | `$domainUuid` | `string`from docblock |
| 2 | `domain_data` | `$domainData` | `array`from docblock |

When it fires (1 site)

-   [`SubdomainsController::show`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L217)[`GET /api/admin/subdomains/{uuid}`](https://featherpanel.com/docs/api/reference/admin/subdomains/#get-admin-subdomains-uuid)

```php
$event->on(SubdomainsEvent::onSubdomainDomainRetrieved(), function ($domainUuid, $domainData): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:retrieved ' . json_encode(['domain_uuid' => $domainUuid, 'domain_data' => $domainData]));
});
```

## `SubdomainsEvent::onSubdomainDomainUpdated()`

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

Docblock: string domain uuid, array old data, array new data. (the emitter passes 4 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domain_uuid` | `$domainUuid` | `string` |
| 2 | `old_data` | `$oldData` | not declared |
| 3 | `new_data` | `$newData` | not declared |
| 4 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

-   [`SubdomainsController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L368)[`PATCH /api/admin/subdomains/{uuid}`](https://featherpanel.com/docs/api/reference/admin/subdomains/#patch-admin-subdomains-uuid)

```php
$event->on(SubdomainsEvent::onSubdomainDomainUpdated(), function ($domainUuid, $oldData, $newData, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domain:updated ' . json_encode(['domain_uuid' => $domainUuid]));
});
```

## `SubdomainsEvent::onSubdomainDomainsRetrieved()`

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

Docblock: array domains list. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `domains` | `$domains` | not declared |
| 2 | `pagination` | `$pagination` | `array` |
| 3 | `filters` | `$filters` | `array` |

When it fires (1 site)

-   [`SubdomainsController::index`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L152)[`GET /api/admin/subdomains`](https://featherpanel.com/docs/api/reference/admin/subdomains/#get-admin-subdomains)

```php
$event->on(SubdomainsEvent::onSubdomainDomainsRetrieved(), function ($domains, $pagination, $filters): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:domains:retrieved ' . json_encode(['pagination' => $pagination, 'filters' => $filters]));
});
```

## `SubdomainsEvent::onSubdomainsError()`

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

Docblock: string error message, array context.

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

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

## `SubdomainsEvent::onSubdomainSettingsUpdated()`

- Name: `featherpanel:admin:subdomains:settings:updated`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SubdomainsEvent.php#L68)

Docblock: array settings data. (the emitter passes 2 values, see the table)

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

When it fires (2 sites)

-   [`SubdomainsController::updateSettings`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L545)
-   [`SubdomainsController::updateSettings`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SubdomainsController.php#L598)

```php
$event->on(SubdomainsEvent::onSubdomainSettingsUpdated(), function ($settings, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:subdomains:settings:updated ' . json_encode(['settings' => $settings]));
});
```

## `SubdomainsEvent::onSubdomainCreated()`

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

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `subdomain_uuid` | `$subdomainUuid`not at every site | not declared |
| 2 | `subdomain_data` | `$subdomainData`not at every site | not declared |
| 3 | `server_data` | `$serverData`not at every site | `array` |
| 4 | `user` | `$user`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `subdomain_uuid`, `subdomain_data`, `server_data`, `user` | 
`SubdomainController::create`

 |
| `user_uuid`, `subdomain_uuid`, `subdomain_data`, `server_data` | 

`CreateSubdomainTool::execute`

 |

When it fires (2 sites)

-   [`SubdomainController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubdomainController.php#L336)[`PUT /api/user/servers/{uuidShort}/subdomains`](https://featherpanel.com/docs/api/reference/user/server/subdomains/#put-user-servers-uuidShort-subdomains)
-   [`CreateSubdomainTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/CreateSubdomainTool.php#L353)

```php
$event->on(SubdomainsEvent::onSubdomainCreated(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:subdomain:created');
});
```

## `SubdomainsEvent::onSubdomainDeleted()`

- Name: `featherpanel:user:subdomain:deleted`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SubdomainsEvent.php#L85)

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `subdomain_uuid` | `$subdomainUuid`not at every site | `string` |
| 2 | `subdomain_data` | `$subdomainData`not at every site | not declared |
| 3 | `server_data` | `$serverData`not at every site | `array` |
| 4 | `user` | `$user`not at every site | not declared |

| Arguments passed | Emitted from |
| --- | --- |
| `subdomain_uuid`, `subdomain_data`, `server_data`, `user` | 
`SubdomainController::delete`

 |
| `user_uuid`, `subdomain_uuid`, `subdomain_data`, `server_data` | 

`DeleteSubdomainTool::execute`

 |

When it fires (2 sites)

-   [`SubdomainController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/Server/SubdomainController.php#L442)[`DELETE /api/user/servers/{uuidShort}/subdomains/{uuid}`](https://featherpanel.com/docs/api/reference/user/server/subdomains/#delete-user-servers-uuidShort-subdomains-uuid)
-   [`DeleteSubdomainTool::execute`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Services/Chatbot/Tools/DeleteSubdomainTool.php#L193)

```php
$event->on(SubdomainsEvent::onSubdomainDeleted(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:subdomain:deleted');
});
```
