You are here

public function WebformCompositeBase::buildExportHeader in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::buildExportHeader()

Build an element's export header.

Parameters

array $element: An element.

array $options: An associative array of export options.

Return value

array An array containing the element's export headers.

Overrides WebformElementBase::buildExportHeader

See also

\Drupal\webform\WebformSubmissionExporterInterface::getDefaultExportOptions

File

src/Plugin/WebformElement/WebformCompositeBase.php, line 755

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function buildExportHeader(array $element, array $options) {
  if ($this
    ->hasMultipleValues($element)) {
    return parent::buildExportHeader($element, $options);
  }
  $composite_elements = $this
    ->getInitializedCompositeElement($element);
  $header = [];
  foreach (RenderElement::children($composite_elements) as $composite_key) {
    $composite_element = $composite_elements[$composite_key];
    if (!Element::isVisibleElement($composite_element)) {
      continue;
    }
    if ($options['header_format'] === 'label' && !empty($composite_element['#title'])) {
      $header[] = $composite_element['#title'];
    }
    else {
      $header[] = $composite_key;
    }
  }
  return $this
    ->prefixExportHeader($header, $element, $options);
}