/** * Build a form to test the tableselect element. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param $element_properties * An array of element properties for the tableselect element. * * @return array * A form with a tableselect element and a submit button. */ function tableselectFormBuilder($form, FormStateInterface $form_state, $element_properties) { list($header, $options) = _form_test_tableselect_get_data(); $form['tableselect'] = $element_properties; $form['tableselect'] += array('#prefix' => '<div id="tableselect-wrapper">', '#suffix' => '</div>', '#type' => 'tableselect', '#header' => $header, '#options' => $options, '#multiple' => FALSE, '#empty' => t('Empty text.'), '#ajax' => array('callback' => 'form_test_tableselect_ajax_callback', 'wrapper' => 'tableselect-wrapper')); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); return $form; }
/** * Build a form to test the tableselect element. * * @param array $form * An associative array containing the structure of the form. * @param array $form_state * An associative array containing the current state of the form. * @param $element_properties * An array of element properties for the tableselect element. * * @return array * A form with a tableselect element and a submit button. */ function tableselectFormBuilder($form, $form_state, $element_properties) { list($header, $options) = _form_test_tableselect_get_data(); $form['tableselect'] = $element_properties; $form['tableselect'] += array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#multiple' => FALSE, '#empty' => t('Empty text.')); $form['submit'] = array('#type' => 'submit', '#value' => t('Submit')); return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state) { list($header, $options) = _form_test_tableselect_get_data(); // Change the data so that the third column has colspan=2. $header['three'] = array('data' => 'Three', 'colspan' => 2); unset($header['four']); // Set the each row so that column 3 is an array. foreach ($options as $name => $row) { $options[$name]['three'] = array($row['three'], $row['four']); unset($options[$name]['four']); } // Combine cells in row 3. $options['row3']['one'] = array('data' => $options['row3']['one'], 'colspan' => 2); unset($options['row3']['two']); $options['row3']['three'] = array('data' => $options['row3']['three'][0], 'colspan' => 2); unset($options['row3']['four']); return $this->tableselectFormBuilder($form, $form_state, array('#header' => $header, '#options' => $options)); }
/** * Test the whether the option checker gives an error on invalid tableselect values for radios. */ function testMultipleFalseOptionchecker() { list($header, $options) = _form_test_tableselect_get_data(); $form['tableselect'] = array('#type' => 'tableselect', '#header' => $header, '#options' => $options, '#multiple' => FALSE); // Test with a valid value. list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => 'row1')); $this->assertFalse(isset($errors['tableselect']), 'Option checker allows valid values for radio buttons.'); // Test with an invalid value. list(, , $errors) = $this->formSubmitHelper($form, array('tableselect' => 'non_existing_value')); $this->assertTrue(isset($errors['tableselect']), 'Option checker disallows invalid values for radio buttons.'); }