You are here

public static function WebformExampleComposite::getCompositeElements in Webform 6.x

Same name and namespace in other branches
  1. 8.5 modules/webform_example_composite/src/Element/WebformExampleComposite.php \Drupal\webform_example_composite\Element\WebformExampleComposite::getCompositeElements()

Get a renderable array of webform elements.

Parameters

array $element: A render array for the current element.

Return value

array A renderable array of webform elements, containing the base properties for the composite's webform elements.

Overrides WebformCompositeBase::getCompositeElements

File

modules/webform_example_composite/src/Element/WebformExampleComposite.php, line 35

Class

WebformExampleComposite
Provides a 'webform_example_composite'.

Namespace

Drupal\webform_example_composite\Element

Code

public static function getCompositeElements(array $element) {
  $elements = [];
  $elements['first_name'] = [
    '#type' => 'textfield',
    '#title' => t('First name'),
  ];
  $elements['last_name'] = [
    '#type' => 'textfield',
    '#title' => t('Last name'),
  ];
  $elements['date_of_birth'] = [
    '#type' => 'date',
    '#title' => t('Date of birth'),
    // Use #after_build to add #states.
    '#after_build' => [
      [
        get_called_class(),
        'afterBuild',
      ],
    ],
  ];
  $elements['sex'] = [
    '#type' => 'select',
    '#title' => t('Sex'),
    '#options' => 'sex',
    // Use #after_build to add #states.
    '#after_build' => [
      [
        get_called_class(),
        'afterBuild',
      ],
    ],
  ];
  return $elements;
}