# SpellsEvent events

> 15 FeatherPanel plugin events on SpellsEvent (7 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/spells/

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

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(SpellsEvent::onSpellsReordered(), function ($realmId, $spells, $reorderedBy): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:reordered ' . json_encode(['realm_id' => $realmId, 'spells' => $spells, 'reordered_by' => $reorderedBy]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `SpellsEvent::onSpellsByRealmRetrieved()`

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

Docblock: int realm id, array spells.

```php
$event->on(SpellsEvent::onSpellsByRealmRetrieved(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:by:realm:retrieved ' . json_encode($args));
});
```

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

## `SpellsEvent::onSpellsError()`

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

Docblock: string error message, array context.

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

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

## `SpellsEvent::onSpellsReordered()`

- Name: `featherpanel:admin:spells:reordered`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SpellsEvent.php#L76)

Docblock: int realm id, array spells, array reordered\_by.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `realm_id` | `$realmId` | `int` |
| 2 | `spells` | `$spells` | `array` |
| 3 | `reordered_by` | `$reorderedBy` | `array`from docblock |

When it fires (1 site)

-   [`SpellsController::reorder`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SpellsController.php#L974)[`POST /api/admin/spells/reorder`](https://featherpanel.com/docs/api/reference/admin/spells/#post-admin-spells-reorder)

```php
$event->on(SpellsEvent::onSpellsReordered(), function ($realmId, $spells, $reorderedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:reordered ' . json_encode(['realm_id' => $realmId, 'spells' => $spells, 'reordered_by' => $reorderedBy]));
});
```

## `SpellsEvent::onSpellsRetrieved()`

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

Docblock: array spells list.

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

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

## `SpellsEvent::onSpellCreated()`

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

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

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

When it fires (1 site)

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

```php
$event->on(SpellsEvent::onSpellCreated(), function ($spell, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:spell:created');
});
```

## `SpellsEvent::onSpellDeleted()`

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

Docblock: int spell id, array spell data.

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

When it fires (1 site)

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

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

## `SpellsEvent::onSpellExported()`

- Name: `featherpanel:admin:spells:spell:exported`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SpellsEvent.php#L92)

Docblock: int spell id, array export data.

```php
$event->on(SpellsEvent::onSpellExported(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:spell:exported ' . json_encode($args));
});
```

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

## `SpellsEvent::onSpellNotFound()`

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

Docblock: int spell id, string error message.

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

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

## `SpellsEvent::onSpellRetrieved()`

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

Docblock: int spell id, array spell data.

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

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

## `SpellsEvent::onSpellUpdated()`

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

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

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

When it fires (1 site)

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

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

## `SpellsEvent::onSpellsImported()`

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

Docblock: array import data, array results.

```php
$event->on(SpellsEvent::onSpellsImported(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:spells:imported ' . json_encode($args));
});
```

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

## `SpellsEvent::onSpellVariableCreated()`

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

Docblock: int spell id, array variable data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `spell_id` | `$spellId` | `int` |
| 2 | `variable` | `$variable` | `array`from docblock |

When it fires (1 site)

-   [`SpellsController::createVariable`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SpellsController.php#L1365)[`POST /api/admin/spells/{spellId}/variables`](https://featherpanel.com/docs/api/reference/admin/spells/#post-admin-spells-spellId-variables)

```php
$event->on(SpellsEvent::onSpellVariableCreated(), function ($spellId, $variable): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:variable:created ' . json_encode(['spell_id' => $spellId, 'variable' => $variable]));
});
```

## `SpellsEvent::onSpellVariableDeleted()`

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

Docblock: int variable id, array variable data. (the emitter passes 1 value, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `variable` | `$variable` | not declared |

When it fires (1 site)

-   [`SpellsController::deleteVariable`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SpellsController.php#L1487)[`DELETE /api/admin/spell-variables/{id}`](https://featherpanel.com/docs/api/reference/admin/spells/#delete-admin-spell-variables-id)

```php
$event->on(SpellsEvent::onSpellVariableDeleted(), function ($variable): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:variable:deleted');
});
```

## `SpellsEvent::onSpellVariableUpdated()`

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

Docblock: int variable id, array old data, array new data. (the emitter passes 2 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `variable` | `$variable` | not declared |
| 2 | `updated_data` | `$updatedData` | not declared |

When it fires (1 site)

-   [`SpellsController::updateVariable`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SpellsController.php#L1431)[`PATCH /api/admin/spell-variables/{id}`](https://featherpanel.com/docs/api/reference/admin/spells/#patch-admin-spell-variables-id)

```php
$event->on(SpellsEvent::onSpellVariableUpdated(), function ($variable, $updatedData): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:spells:variable:updated');
});
```

## `SpellsEvent::onSpellVariablesRetrieved()`

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

Docblock: int spell id, array variables.

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

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