# RealmsEvent events

> 7 FeatherPanel plugin events on RealmsEvent (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/realms/

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

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

    public static function pluginInstall(): void
    {
    }

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

## `RealmsEvent::onRealmsError()`

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

Docblock: string error message, array context.

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

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

## `RealmsEvent::onRealmCreated()`

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

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

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

When it fires (1 site)

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

```php
$event->on(RealmsEvent::onRealmCreated(), function ($realm, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:realms:realm:created');
});
```

## `RealmsEvent::onRealmDeleted()`

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

Docblock: int realm id, array realm data.

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

When it fires (1 site)

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

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

## `RealmsEvent::onRealmNotFound()`

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

Docblock: int realm id, string error message.

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

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

## `RealmsEvent::onRealmRetrieved()`

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

Docblock: int realm id, array realm data.

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

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

## `RealmsEvent::onRealmUpdated()`

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

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

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

When it fires (1 site)

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

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

## `RealmsEvent::onRealmsRetrieved()`

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

Docblock: array realms list.

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

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