diff --git a/core/modules/system/tests/modules/form_test/form_test.module b/core/modules/system/tests/modules/form_test/form_test.module index de5c2f0..a9c585e 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -419,134 +419,6 @@ function _form_test_tableselect_form_builder($form, $form_state, $element_proper } /** - * Test the tableselect #multiple = TRUE functionality. - * - * @deprecated Use \Drupal\form_test\testTableSelectCheckboxes() - */ -function _form_test_tableselect_multiple_true_form($form, $form_state) { - return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => TRUE)); -} - -/** - * Process the tableselect #multiple = TRUE submitted values. - */ -function _form_test_tableselect_multiple_true_form_submit($form, &$form_state) { - $selected = $form_state['values']['tableselect']; - foreach ($selected as $key => $value) { - drupal_set_message(t('Submitted: @key = @value', array('@key' => $key, '@value' => $value))); - } -} - -/** - * Test the tableselect #multiple = FALSE functionality. - * - * @deprecated Use \Drupal\form_test\testTableSelectRadios() - */ -function _form_test_tableselect_multiple_false_form($form, $form_state) { - return _form_test_tableselect_form_builder($form, $form_state, array('#multiple' => FALSE)); -} - -/** - * Test the tableselect #colspan functionality. - * - * @deprecated Use \Drupal\form_test\testTableSelectColspan() - */ -function _form_test_tableselect_colspan_form($form, $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 _form_test_tableselect_form_builder($form, $form_state, array('#header' => $header, '#options' => $options)); -} - -/** - * Process the tableselect #multiple = FALSE submitted values. - */ -function _form_test_tableselect_multiple_false_form_submit($form, &$form_state) { - drupal_set_message(t('Submitted: @value', array('@value' => $form_state['values']['tableselect']))); -} - -/** - * Test functionality of the tableselect #empty property. - * - * @deprecated Use \Drupal\form_test\testTableSelectEmptyText() - */ -function _form_test_tableselect_empty_form($form, $form_state) { - return _form_test_tableselect_form_builder($form, $form_state, array('#options' => array())); -} - -/** - * Test functionality of the tableselect #js_select property. - * - * @deprecated Use \Drupal\form_test\testTableSelectJS() - */ -function _form_test_tableselect_js_select_form($form, $form_state, $action) { - switch ($action) { - case 'multiple-true-default': - $options = array('#multiple' => TRUE); - break; - - case 'multiple-false-default': - $options = array('#multiple' => FALSE); - break; - - case 'multiple-true-no-advanced-select': - $options = array('#multiple' => TRUE, '#js_select' => FALSE); - break; - - case 'multiple-false-advanced-select': - $options = array('#multiple' => FALSE, '#js_select' => TRUE); - break; - } - - return _form_test_tableselect_form_builder($form, $form_state, $options); -} - -/** - * Tests functionality of vertical tabs. - * - * @deprecated Use \Drupal\form_test\testVerticalTabs() - */ -function _form_test_vertical_tabs_form($form, &$form_state) { - $form['vertical_tabs'] = array( - '#type' => 'vertical_tabs', - ); - $form['tab1'] = array( - '#type' => 'details', - '#title' => t('Tab 1'), - '#group' => 'vertical_tabs', - '#access' => user_access('access vertical_tab_test tabs'), - ); - $form['tab1']['field1'] = array( - '#title' => t('Field 1'), - '#type' => 'textfield', - ); - $form['tab2'] = array( - '#type' => 'details', - '#title' => t('Tab 2'), - '#group' => 'vertical_tabs', - '#access' => user_access('access vertical_tab_test tabs'), - ); - $form['tab2']['field2'] = array( - '#title' => t('Field 2'), - '#type' => 'textfield', - ); - return $form; -} - -/** * A multistep form for testing the form storage. * * It uses two steps for editing a virtual "thing". Any changes to it are saved @@ -802,77 +674,6 @@ function form_test_form_state_values_clean_advanced_form_submit($form, &$form_st } /** - * Build a form to test a checkbox. - * - * @deprecated Use \Drupal\form_test\testCheckbox() - */ -function _form_test_checkbox($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - - // A required checkbox. - $form['required_checkbox'] = array( - '#type' => 'checkbox', - '#required' => TRUE, - '#title' => 'required_checkbox', - ); - - // A disabled checkbox should get its default value back. - $form['disabled_checkbox_on'] = array( - '#type' => 'checkbox', - '#disabled' => TRUE, - '#return_value' => 'disabled_checkbox_on', - '#default_value' => 'disabled_checkbox_on', - '#title' => 'disabled_checkbox_on', - ); - $form['disabled_checkbox_off'] = array( - '#type' => 'checkbox', - '#disabled' => TRUE, - '#return_value' => 'disabled_checkbox_off', - '#default_value' => NULL, - '#title' => 'disabled_checkbox_off', - ); - - // A checkbox is active when #default_value == #return_value. - $form['checkbox_on'] = array( - '#type' => 'checkbox', - '#return_value' => 'checkbox_on', - '#default_value' => 'checkbox_on', - '#title' => 'checkbox_on', - ); - - // But inactive in any other case. - $form['checkbox_off'] = array( - '#type' => 'checkbox', - '#return_value' => 'checkbox_off', - '#default_value' => 'checkbox_on', - '#title' => 'checkbox_off', - ); - - // Checkboxes with a #return_value of '0' are supported. - $form['zero_checkbox_on'] = array( - '#type' => 'checkbox', - '#return_value' => '0', - '#default_value' => '0', - '#title' => 'zero_checkbox_on', - ); - - // In that case, passing a #default_value != '0' means that the checkbox is off. - $form['zero_checkbox_off'] = array( - '#type' => 'checkbox', - '#return_value' => '0', - '#default_value' => '1', - '#title' => 'zero_checkbox_off', - ); - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit') - ); - - return $form; -} - -/** * Builds a form to test #type 'select' validation. * * @deprecated Use \Drupal\form_test\testSelect() @@ -1587,31 +1388,6 @@ function _form_test_disabled_elements($form, &$form_state) { } /** - * Build a form to test input forgery of enabled elements. - * - * @deprecated Use \Drupal\form_test\testInputForgery() - */ -function _form_test_input_forgery($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - - // For testing that a user can't submit a value not matching one of the - // allowed options. - $form['checkboxes'] = array( - '#title' => t('Checkboxes'), - '#type' => 'checkboxes', - '#options' => array( - 'one' => 'One', - 'two' => 'Two', - ), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - return $form; -} - -/** * Form builder for testing preservation of values during a rebuild. * * @deprecated Use \Drupal\form_test\testRebuildPreservation() diff --git a/core/modules/system/tests/modules/form_test/form_test.routing.yml b/core/modules/system/tests/modules/form_test/form_test.routing.yml index 3540177..3734665 100644 --- a/core/modules/system/tests/modules/form_test/form_test.routing.yml +++ b/core/modules/system/tests/modules/form_test/form_test.routing.yml @@ -119,7 +119,7 @@ form_test.pattern: form_test.tableselect_checkboxes: path: '/form_test/tableselect/multiple-true' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectCheckboxes' + _form: '\Drupal\form_test\FormTestTableSelectMultipleTrueForm' _title: 'Tableselect checkboxes test' requirements: _access: 'TRUE' @@ -127,7 +127,7 @@ form_test.tableselect_checkboxes: form_test.tableselect_radios: path: '/form_test/tableselect/multiple-false' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectRadios' + _form: '\Drupal\form_test\FormTestTableSelectMultipleFalseForm' _title: 'Tableselect radio button test' requirements: _access: 'TRUE' @@ -135,7 +135,7 @@ form_test.tableselect_radios: form_test.tableselect_colspan: path: '/form_test/tableselect/colspan' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectColspan' + _form: '\Drupal\form_test\FormTestTableSelectColspanForm' _title: 'Tableselect colspan test' requirements: _access: 'TRUE' @@ -143,7 +143,7 @@ form_test.tableselect_colspan: form_test.tableselect_empty_text: path: '/form_test/tableselect/empty-text' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectEmptyText' + _form: '\Drupal\form_test\FormTestTableSelectEmptyForm' _title: 'Tableselect empty text test' requirements: _access: 'TRUE' @@ -151,7 +151,7 @@ form_test.tableselect_empty_text: form_test.tableselect_js: path: '/form_test/tableselect/advanced-select/{test_action}' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectJS' + _form: '\Drupal\form_test\FormTestTableSelectJsSelectForm' _title: 'Tableselect js_select tests' requirements: _access: 'TRUE' @@ -159,7 +159,7 @@ form_test.tableselect_js: form_test.vertical_tabs: path: '/form_test/vertical-tabs' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testVerticalTabs' + _form: '\Drupal\form_test\FormTestVerticalTabsForm' _title: 'Vertical tabs tests' requirements: _access: 'TRUE' @@ -191,7 +191,7 @@ form_test.state_clean_advanced: form_test.checkbox: path: '/form-test/checkbox' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testCheckbox' + _form: '\Drupal\form_test\FormTestCheckboxForm' _title: 'Form test' requirements: _access: 'TRUE' @@ -304,7 +304,7 @@ form_test.disabled_elements: form_test.input_forgery: path: '/form-test/input-forgery' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testInputForgery' + _form: '\Drupal\form_test\FormTestInputForgeryForm' _title: 'Form test' requirements: _access: 'TRUE' diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestCheckboxForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestCheckboxForm.php new file mode 100644 index 0000000..1caa231 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestCheckboxForm.php @@ -0,0 +1,95 @@ + 'checkbox', + '#required' => TRUE, + '#title' => 'required_checkbox', + ); + + // A disabled checkbox should get its default value back. + $form['disabled_checkbox_on'] = array( + '#type' => 'checkbox', + '#disabled' => TRUE, + '#return_value' => 'disabled_checkbox_on', + '#default_value' => 'disabled_checkbox_on', + '#title' => 'disabled_checkbox_on', + ); + $form['disabled_checkbox_off'] = array( + '#type' => 'checkbox', + '#disabled' => TRUE, + '#return_value' => 'disabled_checkbox_off', + '#default_value' => NULL, + '#title' => 'disabled_checkbox_off', + ); + + // A checkbox is active when #default_value == #return_value. + $form['checkbox_on'] = array( + '#type' => 'checkbox', + '#return_value' => 'checkbox_on', + '#default_value' => 'checkbox_on', + '#title' => 'checkbox_on', + ); + + // But inactive in any other case. + $form['checkbox_off'] = array( + '#type' => 'checkbox', + '#return_value' => 'checkbox_off', + '#default_value' => 'checkbox_on', + '#title' => 'checkbox_off', + ); + + // Checkboxes with a #return_value of '0' are supported. + $form['zero_checkbox_on'] = array( + '#type' => 'checkbox', + '#return_value' => '0', + '#default_value' => '0', + '#title' => 'zero_checkbox_on', + ); + + // In that case, passing a #default_value != '0' + // means that the checkbox is off. + $form['zero_checkbox_off'] = array( + '#type' => 'checkbox', + '#return_value' => '0', + '#default_value' => '1', + '#title' => 'zero_checkbox_off', + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestInputForgeryForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestInputForgeryForm.php new file mode 100644 index 0000000..43ab396 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestInputForgeryForm.php @@ -0,0 +1,49 @@ + t('Checkboxes'), + '#type' => 'checkboxes', + '#options' => array( + 'one' => 'One', + 'two' => 'Two', + ), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectColspanForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectColspanForm.php new file mode 100644 index 0000000..e27117a --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectColspanForm.php @@ -0,0 +1,48 @@ + '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 _form_test_tableselect_form_builder($form, $form_state, array('#header' => $header, '#options' => $options)); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectEmptyForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectEmptyForm.php new file mode 100644 index 0000000..dd91a08 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectEmptyForm.php @@ -0,0 +1,32 @@ + array())); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectJsSelectForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectJsSelectForm.php new file mode 100644 index 0000000..cc0292f --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectJsSelectForm.php @@ -0,0 +1,51 @@ + TRUE); + break; + + case 'multiple-false-default': + $options = array('#multiple' => FALSE); + break; + + case 'multiple-true-no-advanced-select': + $options = array('#multiple' => TRUE, '#js_select' => FALSE); + break; + + case 'multiple-false-advanced-select': + $options = array('#multiple' => FALSE, '#js_select' => TRUE); + break; + } + + return _form_test_tableselect_form_builder($form, $form_state, $options);; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleFalseForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleFalseForm.php new file mode 100644 index 0000000..dcfcefc --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleFalseForm.php @@ -0,0 +1,33 @@ + FALSE)); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message(t('Submitted: @value', array('@value' => $form_state['values']['tableselect']))); + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleTrueForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleTrueForm.php new file mode 100644 index 0000000..6aed259 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestTableSelectMultipleTrueForm.php @@ -0,0 +1,36 @@ + TRUE)); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + $selected = $form_state['values']['tableselect']; + foreach ($selected as $key => $value) { + drupal_set_message(t('Submitted: @key = @value', array('@key' => $key, '@value' => $value))); + } + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestVerticalTabsForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestVerticalTabsForm.php new file mode 100644 index 0000000..0e08e76 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestVerticalTabsForm.php @@ -0,0 +1,56 @@ + 'vertical_tabs', + ); + $form['tab1'] = array( + '#type' => 'details', + '#title' => t('Tab 1'), + '#group' => 'vertical_tabs', + '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'), + ); + $form['tab1']['field1'] = array( + '#title' => t('Field 1'), + '#type' => 'textfield', + ); + $form['tab2'] = array( + '#type' => 'details', + '#title' => t('Tab 2'), + '#group' => 'vertical_tabs', + '#access' => \Drupal::currentUser()->hasPermission('access vertical_tab_test tabs'), + ); + $form['tab2']['field2'] = array( + '#title' => t('Field 2'), + '#type' => 'textfield', + ); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + } +}