# NotificationsEvent events

> 8 FeatherPanel plugin events on NotificationsEvent (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/notifications/

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

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(NotificationsEvent::onNotificationNotFound(), function ($notificationId, $errorMessage): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:not:found ' . json_encode(['notification_id' => $notificationId, 'error_message' => $errorMessage]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `NotificationsEvent::onNotificationsError()`

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

Docblock: string error message, array context.

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

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

## `NotificationsEvent::onNotificationCreated()`

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

Docblock: array notification data. (the emitter passes 4 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | not declared |
| 2 | `notification_data` | `$notificationData` | not declared |
| 3 | `created_by` | `$createdBy` | not declared |
| 4 | `emailed` | `$emailed` | not declared |

When it fires (1 site)

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

```php
$event->on(NotificationsEvent::onNotificationCreated(), function ($notificationId, $notificationData, $createdBy, $emailed): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:created');
});
```

## `NotificationsEvent::onNotificationDeleted()`

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

Docblock: int notification id, array notification data. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | `int` |
| 2 | `notification_data` | `$notificationData` | not declared |
| 3 | `deleted_by` | `$deletedBy` | not declared |

When it fires (1 site)

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

```php
$event->on(NotificationsEvent::onNotificationDeleted(), function ($notificationId, $notificationData, $deletedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:deleted ' . json_encode(['notification_id' => $notificationId]));
});
```

## `NotificationsEvent::onNotificationNotFound()`

- Name: `featherpanel:admin:notifications:notification:not:found`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NotificationsEvent.php#L85)

Docblock: int notification id, string error message.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | `int` |
| 2 | `error_message` | `$errorMessage` | `string` |

When it fires (1 site)

-   [`NotificationsController::show`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/NotificationsController.php#L305)[`GET /api/admin/notifications/{id}`](https://featherpanel.com/docs/api/reference/admin/notifications/#get-admin-notifications-id)

```php
$event->on(NotificationsEvent::onNotificationNotFound(), function ($notificationId, $errorMessage): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:not:found ' . json_encode(['notification_id' => $notificationId, 'error_message' => $errorMessage]));
});
```

## `NotificationsEvent::onNotificationRetrieved()`

- Name: `featherpanel:admin:notifications:notification:retrieved`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NotificationsEvent.php#L36)

Docblock: int notification id, array notification data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | `int` |
| 2 | `notification_data` | `$notificationData` | `array`from docblock |

When it fires (1 site)

-   [`NotificationsController::show`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/NotificationsController.php#L320)[`GET /api/admin/notifications/{id}`](https://featherpanel.com/docs/api/reference/admin/notifications/#get-admin-notifications-id)

```php
$event->on(NotificationsEvent::onNotificationRetrieved(), function ($notificationId, $notificationData): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:retrieved ' . json_encode(['notification_id' => $notificationId, 'notification_data' => $notificationData]));
});
```

## `NotificationsEvent::onNotificationUpdated()`

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

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | `int` |
| 2 | `old_data` | `$oldData` | not declared |
| 3 | `new_data` | `$newData` | not declared |
| 4 | `updated_by` | `$updatedBy` | not declared |

When it fires (1 site)

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

```php
$event->on(NotificationsEvent::onNotificationUpdated(), function ($notificationId, $oldData, $newData, $updatedBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:notification:updated ' . json_encode(['notification_id' => $notificationId]));
});
```

## `NotificationsEvent::onNotificationsRetrieved()`

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

Docblock: array notifications list. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notifications` | `$notifications` | not declared |
| 2 | `pagination` | `$pagination` | `array` |
| 3 | `filters` | `$filters` | `array` |

When it fires (1 site)

-   [`NotificationsController::index`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/NotificationsController.php#L227)[`GET /api/admin/notifications`](https://featherpanel.com/docs/api/reference/admin/notifications/#get-admin-notifications)

```php
$event->on(NotificationsEvent::onNotificationsRetrieved(), function ($notifications, $pagination, $filters): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:notifications:retrieved ' . json_encode(['pagination' => $pagination, 'filters' => $filters]));
});
```

## `NotificationsEvent::onNotificationDismissed()`

- Name: `featherpanel:user:notifications:notification:dismissed`
- emitted at 1 site
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/NotificationsEvent.php#L68)

Docblock: int notification id, int user id. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `notification_id` | `$notificationId` | `int` |
| 2 | `user_id` | `$userId` | `int` |
| 3 | `user` | `$user` | not declared |

When it fires (1 site)

-   [`NotificationController::dismiss`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/User/NotificationController.php#L158)[`POST /api/user/notifications/{id}/dismiss`](https://featherpanel.com/docs/api/reference/user/notifications/#post-user-notifications-id-dismiss)

```php
$event->on(NotificationsEvent::onNotificationDismissed(), function ($notificationId, $userId, $user): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:user:notifications:notification:dismissed ' . json_encode(['notification_id' => $notificationId, 'user_id' => $userId]));
});
```
