---
title: "Store Events"
url: https://festi.dev/8.0/Plugins/Modules/docs/StoreEvents/
---

# Store Events

Modules can subscribe to lifecycle events emitted by `ModuleWorkSpacesStore`.

## BeforeUpdateModuleEvent

Triggered before a module record is updated.

**Methods:**
- `getModule()` — returns the `ModuleValuesObject` being updated.

```php
public function onBeforeUpdateModuleHandler(BeforeUpdateModuleEvent $event): void
{
    $module = $event->getModule();
    // logic before the module is updated
}
```

## BeforeUpdateWorkSpaceModuleEvent

Triggered before a workspace-scoped module record is updated.

**Methods:**
- `getModule()` — returns the `ModuleValuesObject`.
- `getWorkSpace()` — returns the `IWorkSpace` context.

```php
public function onBeforeUpdateWorkSpaceModuleHandler(BeforeUpdateWorkSpaceModuleEvent $event): void
{
    $module = $event->getModule();
    $workspace = $event->getWorkSpace();
    // logic before the workspace module is updated
}
```

## IInstallableWorkSpaceModule

A lifecycle hook rather than an event: a workspace module implementing this interface is called
once its **own** status in a workspace has just been written — after `onLoadWorkSpaceModule()` on
enabling. Use it to put in place what the workspace needs to start using the module (a default
record, a setting), and to take it away on disabling. Only the module whose status changes is
called; other modules are not notified.

Both methods run inside the status transaction, so throwing rolls the change back.

```php
use plugin\Modules\domain\scope\IInstallableWorkSpaceModule;

class TestModulePlugin extends DisplayPlugin implements IInstallableWorkSpaceModule
{
    public function onInstallWorkSpaceModule(IWorkSpace $workSpace): void
    {
        // Give the workspace what it needs to start using the module
    }

    public function onUninstallWorkSpaceModule(IWorkSpace $workSpace): void
    {
        // Usually nothing: the workspace keeps its records for the day the module comes back
    }
}
```

## CreateWorkSpaceProviderEvent

Triggered when a workspace provider needs to be resolved.

**Methods:**
- `getWorkSpaceProvider()` — returns the current `IWorkSpaceProvider` or `null`.
- `setWorkSpaceProvider(IWorkSpaceProvider $workSpaceProvider)` — sets the provider.

```php
public function onCreateWorkSpaceProviderHandler(CreateWorkSpaceProviderEvent $event): void
{
    $provider = new MyWorkSpaceProvider();

    $event->setWorkSpaceProvider($provider);
}
```

## BeforeDisplayModuleDictionaryEvent

Triggered before a module's dictionary is displayed in system scope — the page on
`/modules/manage/{idModule}/dictionaries/{ident}/` where the records a workspace template
installs are authored.

One route serves every declared dictionary, so a handler that cares about only one of them
tells them apart by the dictionary on the event.

**Methods:**
- `getStageBuilder()` — the `StageBuilder` the page is built with.
- `getBreadcrumbs()` — the breadcrumbs object, modified in place.
- `getModule()` — the module the dictionary belongs to.
- `getDictionary()` — the dictionary being displayed: ident, caption, table and store class.
- `getParentUrl()` / `setParentUrl()` — where the page returns to, the module catalogue by default.

```php
public function onBeforeDisplayModuleDictionaryHandler(BeforeDisplayModuleDictionaryEvent $event): void
{
    if ($event->getDictionary()->getIdent() !== 'competencies') {
        return;
    }

    $event->setParentUrl($this->getUrl('/somewhere-else/'));
    $event->getBreadcrumbs()->setItems([...]);
}
```
