Skip to content

Commit

Permalink
Add Integrations::EVENT_MODIFY_FORM_INTEGRATION event
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Jun 28, 2024
1 parent 4880ac2 commit 8414992
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
16 changes: 15 additions & 1 deletion docs/developers/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -1560,7 +1560,7 @@ Event::on(Integrations::class, Integrations::EVENT_REGISTER_INTEGRATIONS, functi
```

### The `modifyFormIntegrations` event
The event that is triggered when an integration instance is created for a form. If you want to modify the settings of an integration for a form, this would be a good event to do so.
The event that is triggered when all enabled integrations for a form is prepared for the front-end. This does not change the settings shown for the integration in the form builder.

```php
use verbb\formie\events\ModifyFormIntegrationsEvent;
Expand All @@ -1573,6 +1573,20 @@ Event::on(Integrations::class, Integrations::EVENT_MODIFY_FORM_INTEGRATIONS, fun
});
```

### The `modifyFormIntegration` event
The event that is triggered when an integration instance is created for a form. If you want to modify the settings of an integration for a form, this would be a good event to do so.

```php
use verbb\formie\events\ModifyFormIntegrationEvent;
use verbb\formie\services\Integrations;
use yii\base\Event;

Event::on(Integrations::class, Integrations::EVENT_MODIFY_FORM_INTEGRATION, function(ModifyFormIntegrationEvent $event) {
$integration = $event->integration;
// ...
});
```

### The `beforeSaveIntegration` event
The event that is triggered before an integration is saved.

Expand Down
15 changes: 15 additions & 0 deletions src/events/ModifyFormIntegrationEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace verbb\formie\events;

use verbb\formie\base\IntegrationInterface;

use yii\base\Event;

class ModifyFormIntegrationEvent extends Event
{
// Properties
// =========================================================================

public ?IntegrationInterface $integration = null;

}
18 changes: 16 additions & 2 deletions src/services/Integrations.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use verbb\formie\base\IntegrationInterface;
use verbb\formie\elements\Form;
use verbb\formie\events\IntegrationEvent;
use verbb\formie\events\ModifyFormIntegrationEvent;
use verbb\formie\events\ModifyFormIntegrationsEvent;
use verbb\formie\events\RegisterIntegrationsEvent;
use verbb\formie\integrations\addressproviders;
Expand Down Expand Up @@ -49,6 +50,7 @@ class Integrations extends Component

public const EVENT_REGISTER_INTEGRATIONS = 'registerFormieIntegrations';
public const EVENT_MODIFY_FORM_INTEGRATIONS = 'modifyFormIntegrations';
public const EVENT_MODIFY_FORM_INTEGRATION = 'modifyFormIntegration';
public const EVENT_BEFORE_SAVE_INTEGRATION = 'beforeSaveIntegration';
public const EVENT_AFTER_SAVE_INTEGRATION = 'afterSaveIntegration';
public const EVENT_BEFORE_DELETE_INTEGRATION = 'beforeDeleteIntegration';
Expand Down Expand Up @@ -614,13 +616,25 @@ public function getAllIntegrationsForForm(): array

foreach ($this->getAllCaptchas() as $key => $captcha) {
if ($captcha->getEnabled() && $captcha->hasFormSettings()) {
$grouped[$captcha->typeName()][] = $captcha;
// Fire a 'modifyFormIntegration' event
$event = new ModifyFormIntegrationEvent([
'integration' => $captcha,
]);
$this->trigger(self::EVENT_MODIFY_FORM_INTEGRATION, $event);

$grouped[$captcha->typeName()][] = $event->integration;
}
}

foreach ($this->getAllIntegrations() as $key => $integration) {
if ($integration->getEnabled() && $integration->hasFormSettings()) {
$grouped[$integration->typeName()][] = $integration;
// Fire a 'modifyFormIntegration' event
$event = new ModifyFormIntegrationEvent([
'integration' => $integration,
]);
$this->trigger(self::EVENT_MODIFY_FORM_INTEGRATION, $event);

$grouped[$integration->typeName()][] = $event->integration;
}
}

Expand Down

0 comments on commit 8414992

Please sign in to comment.