PluginProbe
The Innovative Form Builder – IvyForms / 1.5
The Innovative Form Builder – IvyForms v1.5
1.5.1 1.5 1.4.1 1.4 trunk 0.1.2 0.2 0.2.1 0.3 0.3.1 0.4 0.5 0.6 0.6.1 0.6.1-backup 0.6.1.1 0.7 0.8 0.8.1 0.8.2 0.9 0.9.1 1.0 1.1 1.1.1 All 27 releases
ivyforms / backend / src / Services / GoogleSheets / Hooks / GoogleSheetsEntryHooks.php

GoogleSheetsEntryHooks.php in The Innovative Form Builder – IvyForms 1.5, at backend/src/Services/GoogleSheets/Hooks/GoogleSheetsEntryHooks.php

49 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace IvyForms\Services\GoogleSheets\Hooks;
4
5 use IvyForms\Services\GoogleSheets\GoogleSheetsDispatcherService;
6
7 /**
8 * Listens to form submissions and dispatches Google Sheets sync.
9 */
10 class GoogleSheetsEntryHooks
11 {
12 private GoogleSheetsDispatcherService $dispatcher;
13
14 public function __construct(GoogleSheetsDispatcherService $dispatcher)
15 {
16 $this->dispatcher = $dispatcher;
17 }
18
19 public function register(): void
20 {
21 add_action('ivyforms/form/after_submission', [$this, 'onFormSubmission'], 10, 4);
22 }
23
24 /**
25 * @param array<string, mixed> $submissionData
26 * @param array<mixed> $formFields
27 */
28 public function onFormSubmission(int $formId, array $submissionData, array $formFields, ?int $entryId): void
29 {
30 $formattedSubmissionData = $submissionData;
31 $formattedSubmissionData['id'] = $entryId;
32
33 // Defer dispatch until after the submission response is sent. WP-Cron is
34 // unreliable in containerised environments, and serialising form field
35 // entities into transients breaks placeholder resolution on replay.
36 add_action('shutdown', function () use ($formId, $formattedSubmissionData, $formFields): void {
37 if (function_exists('fastcgi_finish_request')) {
38 fastcgi_finish_request();
39 }
40
41 $this->dispatcher->dispatchForSubmission(
42 $formId,
43 $formattedSubmissionData,
44 $formFields
45 );
46 }, 999);
47 }
48 }
49