# AllocationsEvent events

> 7 FeatherPanel plugin events on AllocationsEvent (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/allocations/

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

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(AllocationsEvent::onAllocationCreated(), function ($allocations, $createdCount, $createdBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:allocations:allocation:created ' . json_encode(['allocations' => $allocations, 'created_count' => $createdCount]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `AllocationsEvent::onAllocationCreated()`

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

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `allocations` | `$allocations` | `array` |
| 2 | `created_count` | `$createdCount` | `int` |
| 3 | `created_by` | `$createdBy` | not declared |

When it fires (1 site)

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

```php
$event->on(AllocationsEvent::onAllocationCreated(), function ($allocations, $createdCount, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:allocations:allocation:created ' . json_encode(['allocations' => $allocations, 'created_count' => $createdCount]));
});
```

## `AllocationsEvent::onAllocationDeleted()`

- Name: `featherpanel:admin:allocations:allocation:deleted`
- emitted at 3 sites
- 3 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/AllocationsEvent.php#L60)

Docblock: int allocation id, array allocation data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `allocation` | `$allocation`not at every site | `int`from docblock |
| 2 | `deleted_by` | `$deletedBy`not at every site | `array`from docblock |

| Arguments passed | Emitted from |
| --- | --- |
| `allocation`, `deleted_by` | 
`AllocationsController::delete`

 |
| `deleted_count`, `skipped_count`, `ids`, `deleted_by` | 

`AllocationsController::bulkDelete`

 |
| `deleted_count`, `node_id`, `ip`, `deleted_by` | 

`AllocationsController::deleteUnused`

 |

When it fires (3 sites)

-   [`AllocationsController::delete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/AllocationsController.php#L694)[`DELETE /api/admin/allocations/{id}`](https://featherpanel.com/docs/api/reference/admin/allocations/#delete-admin-allocations-id)
-   [`AllocationsController::bulkDelete`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/AllocationsController.php#L1170)[`DELETE /api/admin/allocations/bulk-delete`](https://featherpanel.com/docs/api/reference/admin/allocations/#delete-admin-allocations-bulk-delete)
-   [`AllocationsController::deleteUnused`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/AllocationsController.php#L1279)[`DELETE /api/admin/allocations/delete-unused`](https://featherpanel.com/docs/api/reference/admin/allocations/#delete-admin-allocations-delete-unused)

```php
$event->on(AllocationsEvent::onAllocationDeleted(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:allocations:allocation:deleted');
});
```

## `AllocationsEvent::onAllocationNotFound()`

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

Docblock: int allocation id, string error message.

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

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

## `AllocationsEvent::onAllocationRetrieved()`

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

Docblock: int allocation id, array allocation data.

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

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

## `AllocationsEvent::onAllocationUpdated()`

- Name: `featherpanel:admin:allocations:allocation:updated`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/AllocationsEvent.php#L52)

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `allocation` | `$allocation`not at every site | `int`from docblock |
| 2 | `updated_data` | `$updatedData`not at every site | `array`from docblock |
| 3 | `updated_by` | `$updatedBy`not at every site | `array`from docblock |

| Arguments passed | Emitted from |
| --- | --- |
| `allocation`, `updated_data`, `updated_by` | 
`AllocationsController::update`

 |
| `node_id`, `from_ip`, `to_ip`, `ip_alias`, `matched_count`, `updated_count`, `deleted_target_conflicts`, `deleted_source_conflicts`, `updated_by` | 

`AllocationsController::bulkUpdateAddress`

 |

When it fires (2 sites)

-   [`AllocationsController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/AllocationsController.php#L615)[`PATCH /api/admin/allocations/{id}`](https://featherpanel.com/docs/api/reference/admin/allocations/#patch-admin-allocations-id)
-   [`AllocationsController::bulkUpdateAddress`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/AllocationsController.php#L1067)[`PATCH /api/admin/allocations/bulk-address`](https://featherpanel.com/docs/api/reference/admin/allocations/#patch-admin-allocations-bulk-address)

```php
$event->on(AllocationsEvent::onAllocationUpdated(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:allocations:allocation:updated');
});
```

## `AllocationsEvent::onAllocationsError()`

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

Docblock: string error message, array context.

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

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

## `AllocationsEvent::onAllocationsRetrieved()`

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

Docblock: array allocations list.

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

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