You are here

public function OptionsBase::buildExportHeader in Webform 8.5

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

Class

OptionsBase
Provides a base 'options' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function buildExportHeader(array $element, array $options) {
  $options_format = $element['#webform_multiple'] ? $options['options_multiple_format'] : $options['options_single_format'];
  if ($options_format === 'separate' && isset($element['#options'])) {
    $header = [];
    foreach ($element['#options'] as $option_value => $option_text) {

      // Note: If $option_text is an array (typically a tableselect row)
      // always use $option_value.
      $title = $options['options_item_format'] === 'key' || is_array($option_text) ? $option_value : $option_text;
      $header[] = $title;
    }

    // Add 'Other' option to header.
    if ($this instanceof WebformElementOtherInterface) {
      $header[] = $options['options_item_format'] === 'key' ? 'other' : $this
        ->t('Other');
    }
    return $this
      ->prefixExportHeader($header, $element, $options);
  }
  else {
    return parent::buildExportHeader($element, $options);
  }
}