You are here

public static function WebformLikert::processWebformLikertAnswers in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformLikert.php \Drupal\webform\Element\WebformLikert::processWebformLikertAnswers()

Get likert element's answer which can include an N/A option.

Parameters

array $element: The element.

2 calls to WebformLikert::processWebformLikertAnswers()
WebformLikert::initialize in src/Plugin/WebformElement/WebformLikert.php
Initialize an element to be displayed, rendered, or exported.
WebformLikert::processWebformLikert in src/Element/WebformLikert.php
Processes a likert scale webform element.

File

src/Element/WebformLikert.php, line 258

Class

WebformLikert
Provides a webform element for a likert scale.

Namespace

Drupal\webform\Element

Code

public static function processWebformLikertAnswers(array &$element) {
  if (empty($element['#na_answer']) || empty($element['#answers'])) {
    return;
  }
  $na_value = !empty($element['#na_answer_value']) ? $element['#na_answer_value'] : (string) t('N/A');
  $na_text = !empty($element['#na_answer_text']) ? $element['#na_answer_text'] : $na_value;
  $element['#answers'] += [
    $na_value => $na_text,
  ];
}