You are here

public function WebformCompositeBase::getTestValues in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformCompositeBase.php \Drupal\webform\Plugin\WebformElement\WebformCompositeBase::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

3 methods override WebformCompositeBase::getTestValues()
Address::getTestValues in src/Plugin/WebformElement/Address.php
Get test values for an element.
WebformLocationGeocomplete::getTestValues in modules/webform_location_geocomplete/src/Plugin/WebformElement/WebformLocationGeocomplete.php
Get test values for an element.
WebformLocationPlaces::getTestValues in src/Plugin/WebformElement/WebformLocationPlaces.php
Get test values for an element.

File

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

Class

WebformCompositeBase
Provides a base for composite elements.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function getTestValues(array $element, WebformInterface $webform, array $options = []) {
  if (empty($element['#webform_composite_elements'])) {
    $this
      ->initialize($element);
  }
  $composite_elements = $this
    ->getInitializedCompositeElement($element);
  $composite_elements = WebformElementHelper::getFlattened($composite_elements);
  $values = [];
  for ($i = 1; $i <= 3; $i++) {

    // Add delta to $options to allow multiple unique managed test files
    // to be created.
    // @see \Drupal\webform\Plugin\WebformElement\WebformManagedFileBase::getTestValues
    $options['delta'] = $i;
    $value = [];
    foreach (RenderElement::children($composite_elements) as $composite_key) {
      $value[$composite_key] = $this->generate
        ->getTestValue($webform, $composite_key, $composite_elements[$composite_key], $options);
    }
    $values[] = $value;
  }
  return $values;
}