You are here

public static function YamlFormExcludedBase::processYamlFormExcluded in YAML Form 8

Processes a form elements form element.

File

src/Element/YamlFormExcludedBase.php, line 35

Class

YamlFormExcludedBase
Provides a base form element for form excluded elements and columns.

Namespace

Drupal\yamlform\Element

Code

public static function processYamlFormExcluded(&$element, FormStateInterface $form_state, &$complete_form) {
  $options = static::getYamlFormExcludedOptions($element);
  $default_value = array_diff(array_keys($options), array_keys($element['#default_value'] ?: []));
  $element['#tree'] = TRUE;
  $element['#element_validate'] = [
    [
      get_called_class(),
      'validateYamlFormExcluded',
    ],
  ];
  $element['tableselect'] = [
    '#type' => 'tableselect',
    '#header' => static::getYamlFormExcludedHeader(),
    '#options' => $options,
    '#js_select' => TRUE,
    '#empty' => t('No elements are available.'),
    '#default_value' => array_combine($default_value, $default_value),
  ];

  // Build tableselect element with selected properties.
  $properties = [
    '#title',
    '#title_display',
    '#description',
    '#description_display',
    '#ajax',
    '#states',
  ];
  $element['tableselect'] += array_intersect_key($element, array_combine($properties, $properties));
  return $element;
}