# SettingsEvent events

> 7 FeatherPanel plugin events on SettingsEvent (4 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/settings/

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

## Setup

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

class MyPlugin implements AppPlugin
{
    public static function processEvents(PluginEvents $event): void
    {
        $event->on(SettingsEvent::onSettingRetrieved(), function ($settingName, $settingData): void {
            App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:setting:retrieved ' . json_encode(['setting_name' => $settingName, 'setting_data' => $settingData]));
        });
    }

    public static function pluginInstall(): void
    {
    }

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

## `SettingsEvent::onSettingsByCategoryRetrieved()`

- Name: `featherpanel:admin:settings:category:retrieved`
- emitted at 2 sites
- 2 payload shapes
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SettingsEvent.php#L36)

Docblock: string category, array settings. (the emitter passes 1 value, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `categories` | `$categories`not at every site | `array` |

| Arguments passed | Emitted from |
| --- | --- |
| `categories` | 
`SettingsController::categories`

 |
| `category`, `category_config`, `settings` | 

`SettingsController::getSettingsByCategory`

 |

When it fires (2 sites)

-   [`SettingsController::categories`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SettingsController.php#L3713)[`GET /api/admin/settings/categories`](https://featherpanel.com/docs/api/reference/admin/settings/#get-admin-settings-categories)
-   [`SettingsController::getSettingsByCategory`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SettingsController.php#L3796)[`GET /api/admin/settings/category/{category}`](https://featherpanel.com/docs/api/reference/admin/settings/#get-admin-settings-category-category)

```php
$event->on(SettingsEvent::onSettingsByCategoryRetrieved(), function (...$rest): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:category:retrieved');
});
```

## `SettingsEvent::onSettingsError()`

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

Docblock: string error message, array context.

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

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

## `SettingsEvent::onSettingsRetrieved()`

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

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

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `settings` | `$settings` | not declared |
| 2 | `categories` | `$categories` | not declared |
| 3 | `organized_settings` | `$organizedSettings` | not declared |

When it fires (1 site)

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

```php
$event->on(SettingsEvent::onSettingsRetrieved(), function ($settings, $categories, $organizedSettings): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:retrieved');
});
```

## `SettingsEvent::onSettingRetrieved()`

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

Docblock: string setting name, array setting data.

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `setting_name` | `$settingName` | `string` |
| 2 | `setting_data` | `$settingData` | `array`from docblock |

When it fires (1 site)

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

```php
$event->on(SettingsEvent::onSettingRetrieved(), function ($settingName, $settingData): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:setting:retrieved ' . json_encode(['setting_name' => $settingName, 'setting_data' => $settingData]));
});
```

## `SettingsEvent::onSettingUpdated()`

- Name: `featherpanel:admin:settings:setting:updated`
- not emitted
- Cancel or modify: no
- [definition](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Plugins/Events/Events/SettingsEvent.php#L60)

Docblock: string setting name, mixed old value, mixed new value.

```php
$event->on(SettingsEvent::onSettingUpdated(), function (...$args): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:setting:updated ' . json_encode($args));
});
```

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

## `SettingsEvent::onSettingsUpdated()`

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

Docblock: array updated settings, array old values. (the emitter passes 3 values, see the table)

| # | Payload key | Listener parameter | Type |
| --- | --- | --- | --- |
| 1 | `updated_settings` | `$updatedSettings` | `array` |
| 2 | `settings_data` | `$settingsData` | not declared |
| 3 | `user` | `$user` | not declared |

When it fires (1 site)

-   [`SettingsController::update`](https://github.com/MythicalLTD/FeatherPanel/blob/15b94e9fc9df233123706b47c42728b81e48cb3d/backend/app/Controllers/Admin/SettingsController.php#L4042)[`PATCH /api/admin/settings`](https://featherpanel.com/docs/api/reference/admin/settings/#patch-admin-settings)

```php
$event->on(SettingsEvent::onSettingsUpdated(), function ($updatedSettings, $settingsData, $user): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:settings:updated ' . json_encode(['updated_settings' => $updatedSettings]));
});
```

## `SettingsEvent::onSettingValidationError()`

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

Docblock: string setting name, string error message.

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

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