You are here

public function YamlFormLikert::buildExportRecord in YAML Form 8

Build an element's export row.

Parameters

array $element: An element.

array $export_options: An associative array of export options.

Return value

array An array containing the element's export row.

Overrides YamlFormElementBase::buildExportRecord

See also

\Drupal\yamlform\YamlFormSubmissionExporterInterface::getDefaultExportOptions

File

src/Plugin/YamlFormElement/YamlFormLikert.php, line 233

Class

YamlFormLikert
Provides a 'likert' element.

Namespace

Drupal\yamlform\Plugin\YamlFormElement

Code

public function buildExportRecord(array $element, $value, array $export_options) {
  $record = [];
  foreach ($element['#questions'] as $question_key => $question_label) {
    $answer_value = isset($value[$question_key]) ? $value[$question_key] : NULL;
    if ($export_options['likert_answers_format'] == 'key') {
      $record[] = $answer_value;
    }
    else {
      $record[] = YamlFormOptionsHelper::getOptionText($answer_value, $element['#answers']);
    }
  }
  return $record;
}