protected function TabularBaseWebformExporter::formatRecordFieldDefinitionValue in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformExporter/TabularBaseWebformExporter.php \Drupal\webform\Plugin\WebformExporter\TabularBaseWebformExporter::formatRecordFieldDefinitionValue()
Get the field definition value from a webform submission entity.
Parameters
array $record: The record to be added to the export file.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $field_definition: The field definition for the value.
1 call to TabularBaseWebformExporter::formatRecordFieldDefinitionValue()
- TabularBaseWebformExporter::buildRecord in src/
Plugin/ WebformExporter/ TabularBaseWebformExporter.php - Build export record using a webform submission.
File
- src/
Plugin/ WebformExporter/ TabularBaseWebformExporter.php, line 124
Class
- TabularBaseWebformExporter
- Defines abstract tabular exporter used to build CSV files and HTML tables.
Namespace
Drupal\webform\Plugin\WebformExporterCode
protected function formatRecordFieldDefinitionValue(array &$record, WebformSubmissionInterface $webform_submission, array $field_definition) {
$export_options = $this
->getConfiguration();
$field_name = $field_definition['name'];
$field_type = $field_definition['type'];
switch ($field_type) {
case 'created':
case 'changed':
case 'timestamp':
if (!empty($webform_submission->{$field_name}->value)) {
$record[] = $this->dateFormatter
->format($webform_submission->{$field_name}->value, 'custom', 'Y-m-d H:i:s');
}
else {
$record[] = '';
}
break;
case 'entity_reference':
$element = [
'#type' => 'entity_autocomplete',
'#target_type' => $field_definition['target_type'],
'#value' => $webform_submission
->get($field_name)->target_id,
];
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $webform_submission, $export_options));
break;
case 'entity_url':
case 'entity_title':
$entity = $webform_submission
->getSourceEntity(TRUE);
if ($entity) {
$record[] = $field_type === 'entity_url' && $entity
->hasLinkTemplate('canonical') ? $entity
->toUrl()
->setOption('absolute', TRUE)
->toString() : $entity
->label();
}
else {
$record[] = '';
}
break;
default:
$record[] = $webform_submission
->get($field_name)->value;
break;
}
}