# DnsHostsEvent events

> 3 FeatherPanel plugin events on DnsHostsEvent (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/dns-hosts/

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(DnsHostsEvent::onDnsHostDeleted(), function ($hostId, $host): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:dns_hosts:host:deleted ' . json_encode(['host_id' => $hostId, 'host' => $host]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `DnsHostsEvent::onDnsHostCreated()`

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

Docblock: array host data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `host` | `$host` | `array`from docblock |

When it fires (1 site)

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

```php
$event->on(DnsHostsEvent::onDnsHostCreated(), function ($host): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:dns_hosts:host:created ' . json_encode(['host' => $host]));
});
```

## `DnsHostsEvent::onDnsHostDeleted()`

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

Docblock: int host id, array host data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `host_id` | `$hostId` | `int` |
| 2 | `host` | `$host` | `array`from docblock |

When it fires (1 site)

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

```php
$event->on(DnsHostsEvent::onDnsHostDeleted(), function ($hostId, $host): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:dns_hosts:host:deleted ' . json_encode(['host_id' => $hostId, 'host' => $host]));
});
```

## `DnsHostsEvent::onDnsHostUpdated()`

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

Docblock: int host id, array host data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `host_id` | `$hostId` | `int` |
| 2 | `host` | `$host` | `array`from docblock |

When it fires (1 site)

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

```php
$event->on(DnsHostsEvent::onDnsHostUpdated(), function ($hostId, $host): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:dns_hosts:host:updated ' . json_encode(['host_id' => $hostId, 'host' => $host]));
});
```
