You are here

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

Same name and namespace in other branches
  1. 8.5 tests/modules/webform_test_element/src/Element/WebformTestComposite.php \Drupal\webform_test_element\Element\WebformTestComposite::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

tests/modules/webform_test_element/src/Element/WebformTestComposite.php, line 17

Class

WebformTestComposite
Provides a webform composite element for testing.

Namespace

Drupal\webform_test_element\Element

Code

public static function getCompositeElements(array $element) {
  $elements = [];
  $elements['textfield'] = [
    '#type' => 'textfield',
    '#title' => t('textfield'),
  ];
  $elements['email'] = [
    '#type' => 'email',
    '#title' => t('email'),
  ];
  $elements['webform_email_confirm'] = [
    '#type' => 'webform_email_confirm',
    '#title' => t('webform_email_confirm'),
  ];
  $elements['tel'] = [
    '#type' => 'tel',
    '#title' => t('tel'),
    '#international' => TRUE,
  ];
  $elements['select'] = [
    '#type' => 'select',
    '#title' => t('select'),
    '#options' => [
      'one' => t('One'),
      'two' => t('Two'),
      'three' => t('Three'),
    ],
    '#select2' => TRUE,
  ];
  $elements['radios'] = [
    '#type' => 'radios',
    '#title' => t('radios'),
    '#options' => [
      'one' => t('One'),
      'two' => t('Two'),
      'three' => t('Three'),
    ],
  ];
  $elements['date'] = [
    '#type' => 'date',
    '#title' => t('date'),
  ];
  $elements['webform_entity_select'] = [
    '#type' => 'webform_entity_select',
    '#title' => t('webform_entity_select'),
    '#target_type' => 'user',
    '#selection_handler' => 'default:user',
    '#selection_settings' => [
      'include_anonymous' => TRUE,
    ],
  ];
  $elements['entity_autocomplete'] = [
    '#type' => 'entity_autocomplete',
    '#title' => t('entity_autocomplete'),
    '#target_type' => 'user',
    '#selection_handler' => 'default:user',
    '#selection_settings' => [
      'include_anonymous' => TRUE,
    ],
  ];
  $elements['datelist'] = [
    '#type' => 'datelist',
    '#title' => t('datelist'),
  ];
  $elements['datetime'] = [
    '#type' => 'datetime',
    '#title' => t('datetime'),
  ];
  $elements['fieldset'] = [
    '#type' => 'fieldset',
    '#title' => t('fieldset'),
  ];
  $elements['fieldset']['nested_tel'] = [
    '#type' => 'tel',
    '#title' => t('nested_tel'),
    '#international' => TRUE,
  ];
  $elements['fieldset']['nested_select'] = [
    '#type' => 'select',
    '#title' => t('nested_select'),
    '#options' => 'days',
  ];
  $elements['fieldset']['nested_radios'] = [
    '#type' => 'radios',
    '#title' => t('nested_radios'),
    '#options' => 'days',
  ];

  // Below elements throw exceptions.
  // @see \Drupal\webform\Element\WebformCompositeBase::processWebformComposite
  // $elements['checkboxes'] = ['#type' => 'checkboxes'];
  // $elements['likert'] = ['#type' => 'webform_likert'];
  // $elements['datetime'] = ['#type' => 'datetime'];
  return $elements;
}