Skip to content

Commit fae9f1e

Browse files
committed
feat: bitform uploaded files data added
1 parent a1b6cea commit fae9f1e

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

includes/Triggers/BitForm/BitFormController.php

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace BitCode\FI\Triggers\BitForm;
44

55
use BitCode\FI\Flow\Flow;
6+
use BitCode\FI\Core\Util\Common;
7+
use BitCode\BitForm\Core\Util\FileHandler;
68

79
final class BitFormController
810
{
@@ -100,24 +102,48 @@ public static function fields($form_id)
100102
return $fields;
101103
}
102104

103-
public static function handle_bitform_submit($formId, $entryId, $formData)
105+
public static function handle_bitform_submit($formId, $entryId, $formData, $files)
104106
{
105-
if (!empty($formId)) {
106-
$data = [];
107-
if ($entryId) {
108-
$data['entry_id'] = $entryId;
109-
}
110-
foreach ($formData as $key => $value) {
111-
if (\is_string($value) && str_contains($value, '__bf__')) {
112-
$data[$key] = explode('__bf__', $value);
113-
} else {
114-
$data[$key] = $value;
107+
if (empty($formId)) {
108+
return;
109+
}
110+
111+
$flows = Flow::exists('BitForm', $formId);
112+
113+
if (empty($flows)) {
114+
return;
115+
}
116+
117+
$data = [
118+
'form_id' => $formId,
119+
'entry_id' => $entryId
120+
];
121+
122+
foreach ($formData as $key => $value) {
123+
$data[$key] = (\is_string($value) && str_contains($value, '__bf__'))
124+
? explode('__bf__', $value)
125+
: $value;
126+
}
127+
128+
if (class_exists(FileHandler::class) && !empty($files)) {
129+
foreach ($files as $fieldKey => $fileGroup) {
130+
if (empty($fileGroup['new_name']) || !\is_array($fileGroup['new_name'])) {
131+
continue;
115132
}
116-
}
117-
if (!empty($formId) && $flows = Flow::exists('BitForm', $formId)) {
118-
Flow::execute('BitForm', $formId, $data, $flows);
133+
134+
$uploadDir = FileHandler::getEntriesFileUploadDir($formId, $entryId);
135+
$fileUrls = [];
136+
137+
foreach ($fileGroup['new_name'] as $filename) {
138+
$filePath = $uploadDir . DIRECTORY_SEPARATOR . $filename;
139+
$fileUrls[] = Common::fileUrl($filePath);
140+
}
141+
142+
$data[$fieldKey] = \count($fileUrls) > 1 ? $fileUrls : reset($fileUrls);
119143
}
120144
}
145+
146+
Flow::execute('BitForm', $formId, $data, $flows);
121147
}
122148

123149
private static function isPluginActive()

includes/Triggers/BitForm/Hooks.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
use BitCode\FI\Core\Util\Hooks;
88
use BitCode\FI\Triggers\BitForm\BitFormController;
99

10-
Hooks::add('bitform_submit_success', [BitFormController::class, 'handle_bitform_submit'], 10, 3);
10+
Hooks::add('bitform_submit_success', [BitFormController::class, 'handle_bitform_submit'], 10, 4);

0 commit comments

Comments
 (0)