| | |
| | | return; |
| | | } |
| | | |
| | | $existing = $meta->get($data['field_name']); |
| | | $existingIds = !empty($existing) ? explode(',', $existing) : []; |
| | | $allIds = array_unique(array_merge($existingIds, $attachmentIds)); |
| | | $fieldType = $data['field_type'] ?? 'single'; |
| | | |
| | | $meta->set($data['field_name'], implode(',', $allIds)); |
| | | if ($fieldType === 'single') { |
| | | // Single field: replace with latest upload |
| | | $meta->set($data['field_name'], end($attachmentIds)); |
| | | } else { |
| | | // Multi field: merge with existing |
| | | $existing = $meta->get($data['field_name']); |
| | | $existingIds = !empty($existing) ? explode(',', $existing) : []; |
| | | $allIds = array_unique(array_merge($existingIds, $attachmentIds)); |
| | | $meta->set($data['field_name'], implode(',', $allIds)); |
| | | } |
| | | } |
| | | |
| | | private function updateFieldValue(array $data, array $results): void |