# LocationsEvent events

> 7 FeatherPanel plugin events on LocationsEvent (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/locations/

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

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

    public static function pluginInstall(): void
    {
    }

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

## `LocationsEvent::onLocationsError()`

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

Docblock: string error message, array context.

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

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

## `LocationsEvent::onLocationCreated()`

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

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

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

When it fires (1 site)

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

```php
$event->on(LocationsEvent::onLocationCreated(), function ($location, $createdBy): void {
    App::getInstance(true)->getLogger()->info('[myplugin] featherpanel:admin:locations:location:created');
});
```

## `LocationsEvent::onLocationDeleted()`

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

Docblock: int location id, array location data.

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

When it fires (1 site)

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

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

## `LocationsEvent::onLocationNotFound()`

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

Docblock: int location id, string error message.

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

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

## `LocationsEvent::onLocationRetrieved()`

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

Docblock: int location id, array location data.

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

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

## `LocationsEvent::onLocationUpdated()`

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

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

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

When it fires (1 site)

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

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

## `LocationsEvent::onLocationsRetrieved()`

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

Docblock: array locations list.

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

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