3 namespace Drupal\form_test\Form;
5 use Drupal\Core\Form\FormStateInterface;
7 class FormTestTableSelectColspanForm extends FormTestTableSelectFormBase {
12 public function getFormId() {
13 return '_form_test_tableselect_colspan_form';
19 public function buildForm(array $form, FormStateInterface $form_state) {
20 list($header, $options) = _form_test_tableselect_get_data();
22 // Change the data so that the third column has colspan=2.
23 $header['three'] = ['data' => 'Three', 'colspan' => 2];
24 unset($header['four']);
25 // Set the each row so that column 3 is an array.
26 foreach ($options as $name => $row) {
27 $options[$name]['three'] = [$row['three'], $row['four']];
28 unset($options[$name]['four']);
30 // Combine cells in row 3.
31 $options['row3']['one'] = ['data' => $options['row3']['one'], 'colspan' => 2];
32 unset($options['row3']['two']);
33 $options['row3']['three'] = ['data' => $options['row3']['three'][0], 'colspan' => 2];
34 unset($options['row3']['four']);
36 return $this->tableselectFormBuilder($form, $form_state, ['#header' => $header, '#options' => $options]);
42 public function submitForm(array &$form, FormStateInterface $form_state) {