You are here

protected static function YamlFormElementStates::buildStateRow in YAML Form 8

Build state row.

Parameters

array $element: The form element.

array $state: The state.

string $table_id: The element's table id.

int $row_index: The row index.

array $ajax_settings: An array containing AJAX callback settings.

Return value

array A render array containing a state table row.

1 call to YamlFormElementStates::buildStateRow()
YamlFormElementStates::processYamlFormStates in src/Element/YamlFormElementStates.php
Expand an email confirm field into two HTML5 email elements.

File

src/Element/YamlFormElementStates.php, line 216

Class

YamlFormElementStates
Provides a form element to edit an element's #states.

Namespace

Drupal\yamlform\Element

Code

protected static function buildStateRow(array $element, array $state, $table_id, $row_index, array $ajax_settings) {
  $state += [
    'state' => '',
    'operator' => 'and',
  ];
  $row = [
    '#attributes' => [
      'class' => [
        'yamlform-states-table--state',
      ],
    ],
  ];
  $row['state'] = [
    '#type' => 'select',
    '#options' => $element['#state_options'],
    '#default_value' => $state['state'],
    '#empty_option' => '',
    '#empty_value' => '',
    '#attributes' => [
      'class' => [
        'js-yamlform-select2',
        'yamlform-select2',
      ],
    ],
  ];
  $row['operator'] = [
    '#type' => 'select',
    '#options' => [
      'and' => t('All'),
      'or' => t('Any'),
    ],
    '#default_value' => $state['operator'],
    '#field_prefix' => t('if'),
    '#field_suffix' => t('of the following is met:'),
    '#wrapper_attributes' => [
      'colspan' => 3,
      'align' => 'left',
    ],
  ];
  $row['operations'] = self::buildOperations($table_id, $row_index, $ajax_settings);
  return $row;
}