3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormStateInterface;
8 * Builds a form to test table selects with different column spans.
12 class FormTestTableSelectColspanForm extends FormTestTableSelectFormBase {
17 public function getFormId() {
18 return '_form_test_tableselect_colspan_form';
24 public function buildForm(array $form, FormStateInterface $form_state) {
25 list($header, $options) = _form_test_tableselect_get_data();
27 // Change the data so that the third column has colspan=2.
28 $header['three'] = ['data' => 'Three', 'colspan' => 2];
29 unset($header['four']);
30 // Set the each row so that column 3 is an array.
31 foreach ($options as $name => $row) {
32 $options[$name]['three'] = [$row['three'], $row['four']];
33 unset($options[$name]['four']);
35 // Combine cells in row 3.
36 $options['row3']['one'] = ['data' => $options['row3']['one'], 'colspan' => 2];
37 unset($options['row3']['two']);
38 $options['row3']['three'] = ['data' => $options['row3']['three'][0], 'colspan' => 2];
39 unset($options['row3']['four']);
41 return $this->tableselectFormBuilder($form, $form_state, ['#header' => $header, '#options' => $options]);
47 public function submitForm(array &$form, FormStateInterface $form_state) {