You are here

public function WebformLikert::getTestValues in Webform 6.x

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

Get test values for an element.

Parameters

array $element: An element.

\Drupal\webform\WebformInterface $webform: A webform.

array $options: Options used to generate a test value.

Return value

mixed A test value for an element.

Overrides WebformElementBase::getTestValues

File

src/Plugin/WebformElement/WebformLikert.php, line 370

Class

WebformLikert
Provides a 'likert' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getTestValues(array $element, WebformInterface $webform, array $options = []) {
  $value = [];
  foreach ($element['#questions'] as $key => $question) {
    $keys = array_keys($element['#answers']);
    $value[$key] = $options['random'] ? $keys[array_rand($keys)] : reset($keys);
  }
  return [
    $value,
  ];
}