You are here

public function WebformCompositeBase::buildExportRecord in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::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/WebformCompositeBase.php, line 782

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function buildExportRecord(array $element, WebformSubmissionInterface $webform_submission, array $export_options) {
  $value = $this
    ->getValue($element, $webform_submission);
  if ($this
    ->hasMultipleValues($element)) {
    $element['#format'] = $export_options['header_format'] === 'label' ? 'list' : 'raw';
    $export_options['multiple_delimiter'] = PHP_EOL . '---' . PHP_EOL;
    return parent::buildExportRecord($element, $webform_submission, $export_options);
  }
  $record = [];
  $composite_elements = $this
    ->getInitializedCompositeElement($element);
  foreach (RenderElement::children($composite_elements) as $composite_key) {
    $composite_element = $composite_elements[$composite_key];
    if (!Element::isVisibleElement($composite_element)) {
      continue;
    }
    if ($export_options['composite_element_item_format'] === 'label' && $composite_element['#type'] !== 'textfield' && !empty($composite_element['#options'])) {
      $record[] = WebformOptionsHelper::getOptionText($value[$composite_key], $composite_element['#options']);
    }
    else {
      $record[] = isset($value[$composite_key]) ? $value[$composite_key] : NULL;
    }
  }
  return $record;
}