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

Conversation

@lippserd
Copy link
Member

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 Jul 12, 2019

@lippserd lippserd requested a review from nilmerg Jul 12, 2019

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 Jul 12, 2019

@nilmerg nilmerg force-pushed the feature/config-form-events-hook-3768 branch from 3386ce8 to 5b450c2 Jul 15, 2019

@nilmerg nilmerg merged commit 0a55df0 into master Jul 15, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@nilmerg nilmerg deleted the feature/config-form-events-hook-3768 branch Jul 15, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.