sanitizer = $sanitizer; $this->tagResolver = $tagResolver; } /** * @inheritDoc */ public function map(NormalizedSubmission $submission, array $mappingSettings): array { $row = []; $customMapping = $mappingSettings['custom_mapping'] ?? []; if (empty($customMapping)) { return $row; } foreach ($customMapping as $item) { $columnName = trim($item['sheet_column'] ?? ''); if ($columnName === '') { continue; } $formFieldId = trim($item['form_field'] ?? ''); $defaultValue = $item['default_value'] ?? ''; // Retrieve matching field value from submission DTO. $value = null; foreach ($submission->getFields() as $field) { if ($field->getId() === $formFieldId) { $value = $field->getValue(); break; } } // Fallback to special metadata tags (e.g. submission_date, page_url) or default value if empty. if ($value === null || $value === '') { $tagKey = '{' . trim($formFieldId, '{}') . '}'; $resolvedTag = $this->tagResolver->resolve($tagKey, $submission); if ($resolvedTag !== $tagKey) { $value = $resolvedTag; } else { $value = $defaultValue; } } // Resolve special tag templates in string values. if (is_string($value)) { $value = $this->tagResolver->resolve($value, $submission); } // Apply formatting instructions if set. $format = $item['formatting'] ?? 'raw'; if ($format === 'uppercase' && is_string($value)) { $value = mb_strtoupper($value, 'UTF-8'); } elseif ($format === 'lowercase' && is_string($value)) { $value = mb_strtolower($value, 'UTF-8'); } $row[$columnName] = $this->sanitizer->sanitize($value); } return $row; } }