"Fossies" - the Fresh Open Source Software Archive

Member "icingaweb2-2.11.4/doc/60-Hooks.md" (26 Jan 2023, 1495 Bytes) of package /linux/www/icingaweb2-2.11.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format (assuming markdown format). Alternatively you can here view or download the uninterpreted source code file. A member file download can also be achieved by clicking within a package contents listing on the according byte size field.

Hooks

ConfigFormEventsHook

The ConfigFormEventsHook allows developers to hook into the handling of configuration forms. It provides three methods:

appliesTo() determines whether the hook should run for a given configuration form. Developers should use instanceof checks in order to decide whether the hook should run or not. If appliesTo() returns false, isValid() and onSuccess() won't get called for this hook.

isValid() is called after the configuration form has been validated successfully. An exception thrown here indicates form errors and prevents the config from being stored. The exception's error message is shown in the frontend automatically. If there are multiple hooks indicating errors, every error will be displayed.

onSuccess() is called after the configuration has been stored successfully. Form handling can't be interrupted here. Any exception will be caught, logged and notified.

Hook example:

namespace Icinga\Module\Acme\ProvidedHook;

use Icinga\Application\Hook\ConfigFormEventsHook;
use Icinga\Forms\ConfigForm;
use Icinga\Forms\Security\RoleForm;

class ConfigFormEvents extends ConfigFormEventsHook
{
    public function appliesTo(ConfigForm $form)
    {
        return $form instanceof RoleForm;
    }

    public function onSuccess(ConfigForm $form)
    {
        $this->updateMyModuleConfig();
    }

    protected function updateMyModuleConfig()
    {
        // ...
    }
}