Refactor Discord and Slack Integration Handlers for Improved Data Formatting (#736)
- Moved the instantiation of FormSubmissionFormatter to ensure consistent handling of submission data across both DiscordIntegration and SlackIntegration classes. - Updated the logic to show hidden fields based on settings, enhancing the flexibility of data presentation in notifications. - Modified StoreFormSubmissionJob to ensure UUIDs are properly converted to strings, improving data integrity. - Simplified the redirect URL field check in FormSubmissionProcessor for better readability. These changes aim to enhance the maintainability and functionality of integration handlers and form submission processing. Co-authored-by: Julien Nahum <julien@nahum.net>
This commit is contained in:
parent
efb2aabe0a
commit
838ab8d846
|
|
@ -37,12 +37,6 @@ class DiscordIntegration extends AbstractIntegrationHandler
|
|||
{
|
||||
$settings = (array) $this->integrationData ?? [];
|
||||
|
||||
$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
|
||||
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
|
||||
$formatter->showHiddenFields();
|
||||
}
|
||||
$formattedData = $formatter->getFieldsWithValue();
|
||||
|
||||
$externalLinks = [];
|
||||
if (Arr::get($settings, 'link_open_form', true)) {
|
||||
$externalLinks[] = '[**🔗 Open Form**](' . $this->form->share_url . ')';
|
||||
|
|
@ -59,6 +53,12 @@ class DiscordIntegration extends AbstractIntegrationHandler
|
|||
$color = hexdec(str_replace('#', '', $this->form->color));
|
||||
$blocks = [];
|
||||
if (Arr::get($settings, 'include_submission_data', true)) {
|
||||
$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
|
||||
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
|
||||
$formatter->showHiddenFields();
|
||||
}
|
||||
$formattedData = $formatter->getFieldsWithValue();
|
||||
|
||||
$submissionString = '';
|
||||
foreach ($formattedData as $field) {
|
||||
$tmpVal = is_array($field['value']) ? implode(',', $field['value']) : $field['value'];
|
||||
|
|
@ -89,6 +89,7 @@ class DiscordIntegration extends AbstractIntegrationHandler
|
|||
];
|
||||
}
|
||||
|
||||
$formattedData = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly()->showHiddenFields()->getFieldsWithValue();
|
||||
$message = Arr::get($settings, 'message', 'New form submission');
|
||||
return [
|
||||
'content' => (new MentionParser($message, $formattedData))->parse(),
|
||||
|
|
|
|||
|
|
@ -37,12 +37,6 @@ class SlackIntegration extends AbstractIntegrationHandler
|
|||
{
|
||||
$settings = (array) $this->integrationData ?? [];
|
||||
|
||||
$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
|
||||
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
|
||||
$formatter->showHiddenFields();
|
||||
}
|
||||
$formattedData = $formatter->getFieldsWithValue();
|
||||
|
||||
$externalLinks = [];
|
||||
if (Arr::get($settings, 'link_open_form', true)) {
|
||||
$externalLinks[] = '*<' . $this->form->share_url . '|🔗 Open Form>*';
|
||||
|
|
@ -56,6 +50,7 @@ class SlackIntegration extends AbstractIntegrationHandler
|
|||
$externalLinks[] = '*<' . $this->form->share_url . '?submission_id=' . $submissionId . '|✍️ ' . $this->form->editable_submissions_button_text . '>*';
|
||||
}
|
||||
|
||||
$formattedData = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly()->showHiddenFields()->getFieldsWithValue();
|
||||
$message = Arr::get($settings, 'message', 'New form submission');
|
||||
$blocks = [
|
||||
[
|
||||
|
|
@ -68,6 +63,12 @@ class SlackIntegration extends AbstractIntegrationHandler
|
|||
];
|
||||
|
||||
if (Arr::get($settings, 'include_submission_data', true)) {
|
||||
$formatter = (new FormSubmissionFormatter($this->form, $this->submissionData))->outputStringsOnly();
|
||||
if (Arr::get($settings, 'include_hidden_fields_submission_data', false)) {
|
||||
$formatter->showHiddenFields();
|
||||
}
|
||||
$formattedData = $formatter->getFieldsWithValue();
|
||||
|
||||
$submissionString = '';
|
||||
foreach ($formattedData as $field) {
|
||||
$tmpVal = is_array($field['value']) ? implode(',', $field['value']) : $field['value'];
|
||||
|
|
|
|||
|
|
@ -136,7 +136,7 @@ class StoreFormSubmissionJob implements ShouldQueue
|
|||
}
|
||||
} else {
|
||||
if ($field['type'] == 'text' && isset($field['generates_uuid']) && $field['generates_uuid']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid() : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? Str::uuid()->toString() : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
} else {
|
||||
if ($field['type'] == 'text' && isset($field['generates_auto_increment_id']) && $field['generates_auto_increment_id']) {
|
||||
$finalData[$field['id']] = ($this->form->is_pro) ? (string) ($this->form->submissions_count + 1) : 'Please upgrade your OpenForm subscription to use our ID generation features';
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ class FormSubmissionProcessor
|
|||
*/
|
||||
private function isFieldUsedInRedirectUrl(Form $form, string $fieldId): bool
|
||||
{
|
||||
return str_contains($form->redirect_url, '{' . $fieldId . '}');
|
||||
return str_contains($form->redirect_url, $fieldId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue