You are here

protected static function WebformElementStates::buildStateRow in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Element/WebformElementStates.php \Drupal\webform\Element\WebformElementStates::buildStateRow()

Build state row.

Parameters

array $element: The 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 WebformElementStates::buildStateRow()
WebformElementStates::processWebformStates in src/Element/WebformElementStates.php
Expand an email confirm field into two HTML5 email elements.

File

src/Element/WebformElementStates.php, line 372

Class

WebformElementStates
Provides a webform element to edit an element's #states.

Namespace

Drupal\webform\Element

Code

protected static function buildStateRow(array $element, array $state, $table_id, $row_index, array $ajax_settings) {
  $state += [
    'state' => '',
    'operator' => 'and',
  ];
  $row = [
    '#attributes' => [
      'class' => [
        'webform-states-table--state',
      ],
    ],
  ];
  $row['state'] = [
    '#type' => 'select',
    '#title' => t('State'),
    '#title_display' => 'invisible',
    '#options' => $element['#state_options'],
    '#default_value' => $state['state'],
    '#empty_option' => t('- Select -'),
    '#wrapper_attributes' => [
      'class' => [
        'webform-states-table--state',
      ],
    ],
    '#error_no_message' => TRUE,
  ];
  $row['operator'] = [
    '#type' => 'select',
    '#title' => t('Operator'),
    '#title_display' => 'invisible',
    '#options' => [
      'and' => t('All'),
      'or' => t('Any'),
      'xor' => t('One'),
    ],
    '#default_value' => $state['operator'],
    '#field_prefix' => t('if'),
    '#field_suffix' => t('of the following is met:'),
    '#wrapper_attributes' => [
      'class' => [
        'webform-states-table--operator',
      ],
      'colspan' => 2,
      'align' => 'left',
    ],
    '#error_no_message' => TRUE,
  ];
  $row['operations'] = static::buildOperations($table_id, $row_index, $ajax_settings);
  if (!$element['#multiple']) {
    unset($row['operations']['remove']);
  }
  return $row;
}