diff --git a/src/Helpers/UtilsApiHelper.php b/src/Helpers/UtilsApiHelper.php index 0cf391d..8be8d03 100644 --- a/src/Helpers/UtilsApiHelper.php +++ b/src/Helpers/UtilsApiHelper.php @@ -176,6 +176,30 @@ public static function getIntegrationApiPublicOutput(array $formDetails, string ); } + /** + * This function will take form details and apply additional data to it before it is processed. + * It is used in both integrations and non integrations like mailer so it can share the same functionality. + * + * @param array $formDetails Data passed from the `getFormDetailsApi` function. + * @return array + */ + public function processCommonSubmitActionFormData(array $formDetails): array + { + // Pre response filter for addon data. + $filterName = UtilsHooksHelper::getFilterName(['block', 'form', 'preResponseAddonData']); + if (\has_filter($filterName)) { + $formDetails[UtilsConfig::FD_ADDON] = \apply_filters($filterName, [], $formDetails); + } + + // Pre response filter for success redirect data. + $filterName = UtilsHooksHelper::getFilterName(['block', 'form', 'preResponseSuccessRedirectData']); + if (\has_filter($filterName)) { + $formDetails[UtilsConfig::FD_SUCCESS_REDIRECT] = UtilsEncryption::encryptor(\wp_json_encode(\apply_filters($filterName, [], $formDetails))); + } + + return $formDetails; + } + /** * Return API error response array. *