Moments
Data filter
Allows modifying form field data before it's shown in the Block Editor or output on the frontend.
Useful if, for example, you want to ensure that all fields fit into a 2-column layout.
Overrides any Block Editor changes!
add_filter('es_forms_integrations_moments_data', 'getIntegrationFilterData', 10, 2);
/**
* Manipulate form fields data before it is sent to the Block Editor.
*
* @param array<mixed> $data Form fields data.
* @param string $formId Form ID.
*
* @return array<mixed>
*/
function getIntegrationFilterData(array $data, string $formId): array
{
foreach ($data as $index => $field) {
$component = $field['component'] ?? '';
if (!$component) {
continue;
}
$name = $field["{$component}Name"] ?? '';
if (!$name) {
continue;
}
switch ($name) {
case 'firstname':
case 'lastname':
$data[$index]["{$component}FieldWidthMobile"] = 12;
$data[$index]["{$component}FieldWidthLarge"] = 6;
$data[$index]["{$component}DisabledOptions"] = array_merge(
$data[$index]["{$component}DisabledOptions"],
[
"{$component}FieldWidthMobile",
"{$component}FieldWidthLarge",
]
);
break;
}
}
return $data;
}
Order filter
Forces a form field order, regardless of how it's set in the Block editor. Fields not modified through the filter will use order in which they're set in the Block editor.
Not all fields need to have an order defined. For example, you may want to make sure firstname
, lastname
and email
are displayed first, but other fields follow their Block editor order.
add_filter('es_forms_integrations_moments_order', 'getIntegrationOrder');
/**
* Forces form field order for the provided fields. For other fields, Block editor order is used.
*
* @return array<string>
*/
function getIntegrationOrder(): array
{
return [
'firstname',
'lastname',
'email',
];
}
Pre-post ID filter
Allows updating item IDs sent to external integrations to which the form data is sent.
add_filter('es_forms_integrations_moments_pre_post_id', 'getIntegrationPrePostId', 10, 3);
/**
* Modifies integration item ID.
*
* @param string $itemId Integration item ID.
* @param array<mixed> $params Params to be sent to the integration.
* @param string $formId Form ID.
*
* @return array<mixed>
*/
function getIntegrationPrePostId(string $itemId, array $params, string $formId): array
{
return $itemId;
}
Pre-post parameters filter
Allows modifying form field data before it's sent to external integration. Useful if you want to make values derived from the sent data, or add new fields.
add_filter('es_forms_integrations_moments_pre_post_params', 'getIntegrationPrePostParams', 10, 2);
/**
* Modifies form field data before it's sent to external integration.
*
* @param array<string, mixed> $params Array of params.
* @param string $formId Form ID.
*
* @return array<string, mixed>
*/
function getIntegrationPrePostParams(array $params, string $formId): array
{
$formSubmissionPageLt = $params['form_submission_page_lt']['value'] ?? '';
if ($formSubmissionPageLt) {
$params['ib-submission-source'] = [
'name' => 'ib-submission-source',
'value' => $formSubmissionPageLt,
'type' => 'text',
'internalType' => '',
];
}
return $params;
}
Pre-Post Event Params
This filter will allow you to add additional params to the body of the Moments integration payload before forms is done preparing the form params.
\add_filter('es_forms_integrations_moments_pre_post_event_params', 'getMomentsPrePostEventParams', 10, 4);
/**
* Moments pre post event params before process.
*
* This filter will allow you to add additional params to the body of the Moments integration payload before forms is done preparing the form params.
*
* @param array<string, mixed> $params Form fields params.
* @param string $eventName Event name value.
* @param array<string, mixed> $map Map value.
* @param string $formId FormId value.
*
* @return array<mixed>
*/
public function getMomentsPrePostEventParams(array $params, string $eventName, array $map, string $formId): array
{
$params['ib-submission-source'] = [
'name' => 'ib-submission-source',
'value' => 'value',
'type' => 'text',
'internalType' => '',
];
return $params;
}
Pre-Post Event Params After
This filter will allow you to add additional params to the body of the Moments integration payload after forms is done preparing the form params.
\add_filter('es_forms_integrations_moments_pre_post_event_params_after', 'getMomentsPrePostEventParamsAfter', 10, 4);
/**
* Moments pre post event params after process.
*
* This filter will allow you to add additional params to the body of the Moments integration payload after forms is done preparing the form params.
*
* @param array<string, mixed> $output Output data.
* @param array<string, mixed> $params Params original list.
* @param string $eventName Event name value.
* @param string $formId FormId value.
*
* @return array<mixed>
*/
public function getMomentsPrePostEventParamsAfter(array $output, array $params, string $eventName, string $formId): array
{
$output['properties']["testKey"] = 'testValue';
return $output;
}