You are here

public function WebformTable::form in Webform 6.x

Same name and namespace in other branches
  1. 8.5 src/Plugin/WebformElement/WebformTable.php \Drupal\webform\Plugin\WebformElement\WebformTable::form()

Gets the actual configuration webform array to be built.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array An associative array contain the element's configuration webform without any default values.

Overrides WebformElementBase::form

File

src/Plugin/WebformElement/WebformTable.php, line 196

Class

WebformTable
Provides a 'webform_table' element.

Namespace

Drupal\webform\Plugin\WebformElement

Code

public function form(array $form, FormStateInterface $form_state) {
  $form = parent::form($form, $form_state);
  $form['table'] = [
    '#type' => 'fieldset',
    '#title' => $this
      ->t('Table settings'),
  ];
  $form['table']['header'] = [
    '#title' => $this
      ->t('Table header'),
    '#type' => 'webform_multiple',
    '#header' => [
      'title' => [
        'data' => $this
          ->t('Header title'),
        'width' => '50%',
      ],
      'attributes' => [
        'data' => $this
          ->t('Header attributes'),
        'width' => '50%',
      ],
    ],
    '#element' => [
      'title' => [
        '#type' => 'textfield',
        '#title' => $this
          ->t('Header title'),
        '#error_no_message' => TRUE,
      ],
      'attributes' => [
        '#type' => 'webform_codemirror',
        '#mode' => 'yaml',
        '#title' => $this
          ->t('Header attributes (YAML)'),
        '#decode_value' => TRUE,
        '#error_no_message' => TRUE,
      ],
    ],
  ];
  $form['table']['caption'] = [
    '#type' => 'textfield',
    '#title' => $this
      ->t('Caption for the table'),
    '#description' => $this
      ->t('A title semantically associated with your table for increased accessibility.'),
    '#maxlength' => 255,
  ];
  $form['table']['sticky'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t('Enable Drupal style "sticky" table headers (Javascript)'),
    '#description' => $this
      ->t("If checked, the table's header will remain visible as the user scrolls through the table."),
    '#return_value' => TRUE,
  ];
  $form['table']['prefix_children'] = [
    '#type' => 'checkbox',
    '#title' => $this
      ->t("Automatically prefix and increment the table's rows and elements"),
    '#description' => $this
      ->t("If checked, all rows and elements within the table will be prefixed with the table's element key and a  incremented numeric value. (i.e. table_01_first_name)"),
    '#return_value' => TRUE,
  ];

  // Update #required label.
  $form['validation']['required_container']['required']['#title'] .= ' <em>' . $this
    ->t('(Display purposes only)') . '</em>';
  $form['validation']['required_container']['required']['#description'] = $this
    ->t('If checked, adds required indicator to the title, if visible. To require individual elements, also tick "Required" under each elements settings.');
  return $form;
}