# PermissionsEvent events

> 7 FeatherPanel plugin events on PermissionsEvent (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/permissions/

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

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

    public static function pluginInstall(): void
    {
    }

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

## `PermissionsEvent::onPermissionsError()`

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

Docblock: string error message, array context.

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

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

## `PermissionsEvent::onPermissionCreated()`

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

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

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

When it fires (1 site)

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

```php
$event->on(PermissionsEvent::onPermissionCreated(), function ($permission, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:permissions:permission:created');
});
```

## `PermissionsEvent::onPermissionDeleted()`

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

Docblock: int permission id, array permission data.

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

When it fires (1 site)

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

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

## `PermissionsEvent::onPermissionNotFound()`

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

Docblock: int permission id, string error message.

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

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

## `PermissionsEvent::onPermissionRetrieved()`

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

Docblock: int permission id, array permission data.

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

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

## `PermissionsEvent::onPermissionUpdated()`

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

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

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

When it fires (1 site)

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

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

## `PermissionsEvent::onPermissionsRetrieved()`

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

Docblock: array permissions list.

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

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