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

Release 3.0.0 #11

Merged
merged 24 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Config/UtilsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,11 @@ class UtilsConfig
public const FD_FIELDS_ONLY = 'fieldsOnly';
public const FD_FILES_UPLOAD = 'filesUpload';
public const FD_ACTION = 'action';
public const FD_SECURE_DATA = 'secureData';
public const FD_ACTION_EXTERNAL = 'actionExternal';
public const FD_API_STEPS = 'apiSteps';
public const FD_CAPTCHA = 'captcha';
public const FD_STORAGE = 'storage';
public const FD_EMAIL_RESPONSE_TAGS = 'emailResponseTags';
public const FD_IS_VALID = 'isValid';
public const FD_IS_API_VALID = 'isApiValid';
public const FD_LABEL = 'label';
Expand All @@ -505,9 +505,9 @@ class UtilsConfig
public const FD_FIELD_NAMES_FULL = 'fieldNamesFull';
public const FD_STEPS_SETUP = 'stepsSetup';
public const FD_RESPONSE_OUTPUT_DATA = 'responseOutputData';
public const FD_ADDON = 'addon';
public const FD_SUCCESS_REDIRECT = 'successRedirect';
public const FD_ENTRY_ID = 'entryId';

// Never use this param as it is only of fallback purposes.
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
public const FD_PARAMS_ORIGINAL_DEBUG = 'paramsOriginalDebug';

// ------------------------------------------------------------------
// Integration API response details data Keys
Expand Down
22 changes: 0 additions & 22 deletions src/Helpers/UtilsApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,6 @@ public static function getIntegrationSuccessInternalOutput(array $details, array
);
}

/**
* Get api public output additional data used on both integrations and none integrations.
*
* @param array<string, mixed> $formDetails Data passed from the `getFormDetailsApi` function.
*
* @return array<string, mixed>
*/
public static function getApiPublicAdditionalDataOutput(array $formDetails): array
{
$output = [];

if (isset($formDetails[UtilsConfig::FD_SUCCESS_REDIRECT]) && $formDetails[UtilsConfig::FD_SUCCESS_REDIRECT]) {
$output[UtilsHelper::getStateResponseOutputKey('successRedirect')] = $formDetails[UtilsConfig::FD_SUCCESS_REDIRECT];
}

if (isset($formDetails[UtilsConfig::FD_ADDON]) && $formDetails[UtilsConfig::FD_ADDON]) {
$output[UtilsHelper::getStateResponseOutputKey('addon')] = $formDetails[UtilsConfig::FD_ADDON];
}

return $output;
}

/**
* Return API error response array.
*
Expand Down
14 changes: 12 additions & 2 deletions src/Helpers/UtilsHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,25 @@ public static function getStateResponseOutputKey(string $name): string
return self::getStateResponseOutputKeys()[$name] ?? '';
}

/**
* Return successRedirectUrlKeys enum values.
*
* @return array<string>
*/
public static function getStateSuccessRedirectUrlKeys(): array
{
return self::getUtilsManifest()['enums']['successRedirectUrlKeys'] ?? [];
}

/**
* Return successRedirectUrlKeys enum value by name.
*
* @param string $name Name of the enum.
*
* @return string
*/
public static function getStateSuccessRedirectUrlKeys(string $name): string
public static function getStateSuccessRedirectUrlKey(string $name): string
{
return self::getUtilsManifest()['enums']['successRedirectUrlKeys'][$name] ?? '';
return self::getStateSuccessRedirectUrlKeys()[$name] ?? '';
}
}
57 changes: 57 additions & 0 deletions src/Rest/Routes/AbstractUtilsBaseRoute.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,25 @@ static function ($item) {

$output = [];

// These are required keys for each field.
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
$reqKeys = [
'name' => '',
'value' => '',
'type' => '',
'custom' => '',
'typeCustom' => '',
];

$paramsBroken = false;

// If this route is for public form prepare all params.
foreach ($paramsOutput as $key => $value) {
// Check if all required keys are present and baiout if not.
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
if (!\is_array($value) || \array_diff_key($reqKeys, $value)) {
$paramsBroken = true;
break;
}

switch ($key) {
// Used for direct import from settings.
case UtilsHelper::getStateParam('direct'):
Expand All @@ -244,6 +261,10 @@ static function ($item) {
$output['type'] = $value['value'];
$output['params'][$key] = $value;
break;
case UtilsHelper::getStateParam('secureData'):
$output['secureData'] = $value['value'];
$output['params'][$key] = $value;
break;
case UtilsHelper::getStateParam('action'):
$output['action'] = $value['value'];
$output['params'][$key] = $value;
Expand Down Expand Up @@ -319,6 +340,11 @@ function ($item) {
}
}

// Bailout if we have any broken param.
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
if ($paramsBroken) {
return [];
}

return $output;
}

Expand Down Expand Up @@ -462,6 +488,9 @@ protected function getFormDetailsApi($request): array
// Populare files on upload. Only populated on file upload.
$output[UtilsConfig::FD_FILES_UPLOAD] = $this->prepareFile($request->get_file_params(), $params['params'] ?? []);

// Populare action.
iruzevic marked this conversation as resolved.
Show resolved Hide resolved
$output[UtilsConfig::FD_SECURE_DATA] = $params['secureData'] ?? '';

// Populare action.
$output[UtilsConfig::FD_ACTION] = $params['action'] ?? '';

Expand All @@ -480,6 +509,9 @@ protected function getFormDetailsApi($request): array
// Get form storage from params.
$output[UtilsConfig::FD_STORAGE] = \json_decode($params['storage'] ?? '', true) ?? [];

// Set debug original params.
$output[UtilsConfig::FD_PARAMS_ORIGINAL_DEBUG] = $this->getParamsOriginalDebug($request);

return $output;
}

Expand Down Expand Up @@ -510,4 +542,29 @@ private function getFormDetailsApiDirectImport(array $params): array

return $output;
}

/**
* Get params original debug.
*
* @param mixed $request Data got from endpoint url.
*
* @return string
*/
private function getParamsOriginalDebug($request): string
{
$params = $this->getRequestParams($request);

$cleanParams = [
'captcha' => '',
'storage' => '',
];

foreach ($cleanParams as $key => $value) {
if (isset($params[UtilsHelper::getStateParam($key)])) {
unset($params[UtilsHelper::getStateParam($key)]);
}
}

return \sanitize_text_field(\wp_json_encode($params));
}
}
20 changes: 15 additions & 5 deletions src/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@
"direct": "es-form-direct",
"itemId": "es-form-item-id",
"innerId": "es-form-inner-id",
"skippedParams": "es-form-skipped"
"skippedParams": "es-form-skipped",
"secureData": "es-form-secure-data"
},
"attrs": {
"formType": "data-form-type",
Expand All @@ -216,6 +217,7 @@
"fieldTypeCustom": "data-type-custom",
"fieldUncheckedValue": "data-unchecked-value",

"formSecureData": "data-secure-data",
"trackingEventName": "data-tracking-event-name",
"trackingAdditionalData": "data-tracking-additional-data",
"tracking": "data-tracking",
Expand Down Expand Up @@ -275,19 +277,27 @@
},
"responseOutputKeys": {
"validation": "validation",
"processExternally": "processExternally",
"addon": "addonData",
"successRedirect": "successRedirectData",
"successRedirectUrl": "successRedirectUrl",
"successRedirectBaseUrl": "successRedirectBaseUrl",
"file": "file",
"stepType": "stepType",
"stepNextStep": "stepNextStep",
"stepProgressBarItems": "stepProgressBarItems",
"stepIsDisableNextButton": "stepIsDisableNextButton",
"resultOutputItems": "resultOutputItems",
"resultOutputParts": "resultOutputParts"
"trackingEventName": "trackingEventName",
"trackingAdditionalData": "trackingAdditionalData",
"hideGlobalMsgOnSuccess": "hideGlobalMsgOnSuccess",
"hideFormOnSuccess": "hideFormOnSuccess",
"variation": "variation",
"entry": "entry",
"formId": "formId"
},
"successRedirectUrlKeys": {
"variation": "es-variation",
"downloads": "es-downloads",
"entry": "es-entry",
"customResultOutput": "es-ro",
"data": "es-data"
}
}
Expand Down