protected function TabularBaseYamlFormExporter::formatRecordFieldDefinitionValue in YAML Form 8
Get the field definition value from a form submission entity.
Parameters
array $record: The record to be added to the export file.
\Drupal\yamlform\YamlFormSubmissionInterface $yamlform_submission: A form submission.
array $field_definition: The field definition for the value.
1 call to TabularBaseYamlFormExporter::formatRecordFieldDefinitionValue()
- TabularBaseYamlFormExporter::buildRecord in src/
Plugin/ YamlFormExporter/ TabularBaseYamlFormExporter.php - Build export record using a form submission.
File
- src/
Plugin/ YamlFormExporter/ TabularBaseYamlFormExporter.php, line 108
Class
- TabularBaseYamlFormExporter
- Defines abstract tabular exporter used to build CSV files and HTML tables.
Namespace
Drupal\yamlform\Plugin\YamlFormExporterCode
protected function formatRecordFieldDefinitionValue(array &$record, YamlFormSubmissionInterface $yamlform_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':
$record[] = date('Y-m-d H:i:s', $yamlform_submission
->get($field_name)->value);
break;
case 'entity_reference':
$element = [
'#type' => 'entity_autocomplete',
'#target_type' => $field_definition['target_type'],
];
$value = $yamlform_submission
->get($field_name)->target_id;
$record = array_merge($record, $this->elementManager
->invokeMethod('buildExportRecord', $element, $value, $export_options));
break;
case 'entity_url':
case 'entity_title':
if (empty($yamlform_submission->entity_type->value) || empty($yamlform_submission->entity_id->value)) {
$record[] = '';
break;
}
$entity_type = $yamlform_submission->entity_type->value;
$entity_id = $yamlform_submission->entity_id->value;
$entity = $this->entityTypeManager
->getStorage($entity_type)
->load($entity_id);
if ($entity) {
$record[] = $field_type == 'entity_url' ? $entity
->toUrl()
->setOption('absolute', TRUE)
->toString() : $entity
->label();
}
else {
$record[] = '';
}
break;
default:
$record[] = $yamlform_submission
->get($field_name)->value;
break;
}
}