# NodesEvent events

> 9 FeatherPanel plugin events on NodesEvent (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/nodes/

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. 6 of these events are declared but no code emits them yet; they are marked not emitted.

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(NodesEvent::onNodeDeleted(), function ($node, $deletedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:deleted ' . json_encode(['node' => $node, 'deleted_by' => $deletedBy]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `NodesEvent::onNodesError()`

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

Docblock: string error message, array context.

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

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

## `NodesEvent::onNodeConnectionError()`

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

Docblock: int node id, string error message.

```php
$event->on(NodesEvent::onNodeConnectionError(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:connection:error ' . json_encode($args));
});
```

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

## `NodesEvent::onNodeCreated()`

- Name: `featherpanel:admin:nodes:node:created`
- emitted at 2 sites
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NodesEvent.php#L44)

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

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

When it fires (2 sites)

-   [`NodesController::create`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/NodesController.php#L468)[`PUT /api/admin/nodes`](https://featherpanel.com/docs/api/reference/admin/nodes/#put-admin-nodes)
-   [`PterodactylImporterController::importNode`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/PterodactylImporterController.php#L573)[`POST /api/admin/pterodactyl-importer/import-node`](https://featherpanel.com/docs/api/reference/admin/pterodactyl-importer/#post-admin-pterodactyl-importer-import-node)

```php
$event->on(NodesEvent::onNodeCreated(), function ($node, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:created');
});
```

## `NodesEvent::onNodeDeleted()`

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

Docblock: int node id, array node data.

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

When it fires (1 site)

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

```php
$event->on(NodesEvent::onNodeDeleted(), function ($node, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:deleted ' . json_encode(['node' => $node, 'deleted_by' => $deletedBy]));
});
```

## `NodesEvent::onNodeKeyReset()`

- Name: `featherpanel:admin:nodes:node:key:reset`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NodesEvent.php#L68)

Docblock: int node id, string new key.

```php
$event->on(NodesEvent::onNodeKeyReset(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:key:reset ' . json_encode($args));
});
```

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

## `NodesEvent::onNodeNotFound()`

- Name: `featherpanel:admin:nodes:node:not:found`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NodesEvent.php#L85)

Docblock: int node id, string error message.

```php
$event->on(NodesEvent::onNodeNotFound(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:not:found ' . json_encode($args));
});
```

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

## `NodesEvent::onNodeRetrieved()`

- Name: `featherpanel:admin:nodes:node:retrieved`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NodesEvent.php#L36)

Docblock: int node id, array node data.

```php
$event->on(NodesEvent::onNodeRetrieved(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:retrieved ' . json_encode($args));
});
```

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

## `NodesEvent::onNodeUpdated()`

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

Docblock: int node id, array old data, array new data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `node` | `$node` | `int`from docblock |
| 2 | `updated_data` | `$updatedData` | `array`from docblock |
| 3 | `updated_by` | `$updatedBy` | `array`from docblock |

When it fires (1 site)

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

```php
$event->on(NodesEvent::onNodeUpdated(), function ($node, $updatedData, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:node:updated ' . json_encode(['node' => $node, 'updated_data' => $updatedData, 'updated_by' => $updatedBy]));
});
```

## `NodesEvent::onNodesRetrieved()`

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

Docblock: array nodes list.

```php
$event->on(NodesEvent::onNodesRetrieved(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:nodes:retrieved ' . json_encode($args));
});
```

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