Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ConfigFormEventsHook #3862

Merged
merged 6 commits into from
Jul 15, 2019
Merged

Conversation

lippserd
Copy link
Member

@lippserd lippserd commented Jul 12, 2019

fixes #3768

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

  • appliesTo()
  • isValid()
  • onSuccess()

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()
    {
        // ...
    }
}

@lippserd lippserd added this to the 2.7.0 milestone Jul 12, 2019
@lippserd lippserd force-pushed the feature/config-form-events-hook-3768 branch from cfbae4e to 424ee4a Compare July 12, 2019 12:17
@lippserd lippserd requested a review from nilmerg July 12, 2019 12:17
application/forms/ConfigForm.php Outdated Show resolved Hide resolved
@lippserd lippserd force-pushed the feature/config-form-events-hook-3768 branch from 424ee4a to 3386ce8 Compare July 12, 2019 14:12
@nilmerg nilmerg added area/configuration Affects the configuration area/framework Affects third party integration/development enhancement New feature or improvement labels Jul 15, 2019
@nilmerg nilmerg force-pushed the feature/config-form-events-hook-3768 branch from 3386ce8 to 5b450c2 Compare July 15, 2019 05:55
@nilmerg nilmerg merged commit 0a55df0 into master Jul 15, 2019
@nilmerg nilmerg deleted the feature/config-form-events-hook-3768 branch July 15, 2019 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/configuration Affects the configuration area/framework Affects third party integration/development enhancement New feature or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to hook into a configuration form's handling
2 participants