public function OptionsBase::buildExportRecord in Webform 6.x
Same name and namespace in other branches
- 8.5 src/Plugin/WebformElement/OptionsBase.php \Drupal\webform\Plugin\WebformElement\OptionsBase::buildExportRecord()
Build an element's export row.
Parameters
array $element: An element.
\Drupal\webform\WebformSubmissionInterface $webform_submission: A webform submission.
array $export_options: An associative array of export options.
Return value
array An array containing the element's export row.
Overrides WebformElementBase::buildExportRecord
See also
\Drupal\webform\WebformSubmissionExporterInterface::getDefaultExportOptions
File
- src/
Plugin/ WebformElement/ OptionsBase.php, line 648
Class
- OptionsBase
- Provides a base 'options' element.
Namespace
Drupal\webform\Plugin\WebformElementCode
public function buildExportRecord(array $element, WebformSubmissionInterface $webform_submission, array $export_options) {
$element_options = isset($element['#options']) ? $element['#options'] : [];
$options_format = $element['#webform_multiple'] ? $export_options['options_multiple_format'] : $export_options['options_single_format'];
if ($options_format === 'separate') {
$value = $this
->getRawValue($element, $webform_submission);
$record = [];
// Combine the values so that isset can be used instead of in_array().
// http://stackoverflow.com/questions/13483219/what-is-faster-in-array-or-isset
$deltas = FALSE;
if (is_array($value)) {
$value = array_combine($value, $value);
$deltas = $this->exportDelta ? array_flip(array_values($value)) : FALSE;
}
// Separate multiple values (i.e. options).
foreach ($element_options as $option_value => $option_text) {
if (is_array($value) && isset($value[$option_value])) {
unset($value[$option_value]);
$record[] = $deltas ? $deltas[$option_value] + 1 : 'X';
}
elseif ($value === $option_value) {
$value = '';
$record[] = $deltas ? $deltas[$option_value] + 1 : 'X';
}
else {
$record[] = '';
}
}
// Add 'Other' option to record.
if ($this instanceof WebformElementOtherInterface) {
$record[] = is_array($value) ? implode($export_options['multiple_delimiter'], $value) : $value;
}
return $record;
}
else {
if ($export_options['options_item_format'] === 'key') {
$element['#format'] = 'raw';
}
return parent::buildExportRecord($element, $webform_submission, $export_options);
}
}