Express Forms Express Forms for Craft
2.x Discontinued

WARNING

The Express Forms plugin has been discontinued. Please see the Freeform migration guide for more information.


Integration Events

If you wish to extend the capabilities of API Integrations in Express Forms, feel free to use any of the events listed below:

When the Resource Fields have had Their Values Mapped, Ready for Pushing

The EVENT_AFTER_SET_MAPPING event is called when the all of the field values have been mapped and are ready for being pushed to the API. Use this event to attach any additional data to the payload if needed.

use Solspace\ExpressForms\integrations\types\Salesforce;
use Solspace\ExpressForms\events\integrations\IntegrationValueMappingEvent;

Event::on(
    Salesforce::class,
    Salesforce::EVENT_AFTER_SET_MAPPING,
    function (IntegrationValueMappingEvent $event) {
        $values = $event->getMappedValues();
        $values['Custom_Creation_Date__c'] = date('Y-m-d');

        $event->setMappedValues($values);
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13

After Getting a Response when Pushing Objects to the API

The EVENT_AFTER_RESPONSE event is useful if you need to do something with the returned response data from an integration, such as store the new ID somewhere.

Using Salesforce as an example:

use Solspace\ExpressForms\integrations\types\Salesforce;
use Solspace\ExpressForms\events\integrations\PushResponseEvent;

Event::on(
    Salesforce::class,
    Salesforce::EVENT_AFTER_RESPONSE,
    function (PushResponseEvent $event) {
        $response = $event->getResponse();

        $data = json_decode((string) $response->getBody());
        // Store the $data->id somewhere
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13

When Fetching Resources

The EVENT_FETCH_RESOURCES event is fired after all of the integration type resources have been fetched. You can add custom resources resources if you so desire.

use Solspace\ExpressForms\integrations\types\Salesforce;
use Solspace\ExpressForms\events\integrations\FetchResourcesEvent;
use Solspace\ExpressForms\integrations\dto\Resource;

Event::on(
    Salesforce::class,
    Salesforce::EVENT_FETCH_RESOURCES,
    function (FetchResourcesEvent $event) {
        // We attach a custom resource
        $event->addResource(
            new Resource(
                $event->getIntegrationType(),
                'My custom resource',
                'my_custom_resource_id'
            )
        )
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

When Fetching Resource Fields

The EVENT_FETCH_RESOURCE_FIELDS event is fired after all of the resource fields have been fetched for a particular resource. It can be used to attach extra fields for a particular resource.

use Solspace\ExpressForms\integrations\types\Salesforce;
use Solspace\ExpressForms\events\integrations\FetchResourceFieldsEvent;
use Solspace\ExpressForms\integrations\dto\ResourceField;

Event::on(
    Salesforce::class,
    Salesforce::EVENT_FETCH_RESOURCE_FIELDS,
    function (FetchResourceFieldsEvent $event) {
        if (!$event->getIntegrationType() instanceof Salesforce || $event->getResourceId() !== 'specific_resource_id') {
            return;
        }

        // We attach a custom resource field
        $event->addResourceField(
            new ResourceField(
                'My custom field',
                'my_custom_field_id',
                'string'
            )
        )
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

When Populating an Integration Mapping Object from Array Data

Before Building the Integration Mapping Object

The EVENT_BEFORE_BUILD_FROM_ARRAY event is called before the integration mapping object is populated with values.

TIP

This is a cancelable event, so you could cancel the building process if needed.

use Solspace\ExpressForms\factories\IntegrationMappingFactory;
use Solspace\ExpressForms\events\integrations\MappingBuildFromArrayEvent;

Event::on(
    IntegrationMappingFactory::class,
    IntegrationMappingFactory::EVENT_BEFORE_BUILD_FROM_ARRAY,
    function (MappingBuildFromArrayEvent $event) {
        $mappingData = $event->getMappingData();

        // Delete every other mapping
        $counter = 0;
        foreach ($mappingData as $key => $value) {
            if ($counter++ % 2 === 0) {
                unset($mappingData[$key]);
            }
        }

        $event->setMappingData($mappingData);
    }
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

After Building the Integration Mapping Object

The EVENT_AFTER_BUILD_FROM_ARRAY event is fired after the integration mapping object is built and before it's returned.

TIP

This is a cancelable event, so you could cancel the building process if needed.

use Solspace\ExpressForms\factories\IntegrationMappingFactory;
use Solspace\ExpressForms\events\integrations\MappingAfterBuildFromArrayEvent;

Event::on(
    IntegrationMappingFactory::class,
    IntegrationMappingFactory::EVENT_AFTER_BUILD_FROM_ARRAY,
    function (MappingAfterBuildFromArrayEvent $event) {
        $mappingCollection = $event->getMappingCollection();

        // Do something here...
    }
);
1
2
3
4
5
6
7
8
9
10
11
12