Fundamentals

Read module configuration

A detailled explanation of our config service can be found here.

Retrieve config value

To use the module configuration, you can simply use the following function.

The first parameter defines the config key, the second the Saleschannel ID (false if the channel should be automatically detected, default) and the third defines the default value if this config value was not yet configured.

$configValue = app(ConfigService::class)->get('core.domain.status', false, null);

To retreive a config value in a twig template, you can use this function with the identical parameters:

{% set configValue = config('core.domain.status', false, null) %}

Listen to the config save

Read our documentation for listening to events first. This is just a quick example.

In your module directory at /Providers/, create an event service provider, e.g.:

HwMollieEventServiceProvider.php

<?php

namespace custom\modules\HwMollie\Providers;

use App\Events\ConfigElementsChangedEvent;
use custom\modules\HwMollie\Listeners\ConfigChangedListener;
use Illuminate\Foundation\Support\Providers\EventServiceProvider;

class HwMollieEventServiceProvider extends EventServiceProvider
{
    protected $listen = [
        ConfigElementsChangedEvent::class => [
            ConfigChangedListener::class // This is the event listener you have to create in the next step!
        ]
    ];
}

Now add your event service provider to the modules.json as a child to the parameter "providers", e.g.:

In your event listener, you can handle the ConfigElementsChanged event and check if any configuration of your module was changed.

Please note that every configuration change will trigger this event, even from other modules. Therefore you need to check if any config item from your module was changed.

Was this helpful?