diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php index 3f6d518..7903a2c 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/FormTest.php @@ -162,8 +162,8 @@ function testRequiredFields() { * @see form_test_validate_required_form() */ function testRequiredCheckboxesRadio() { - $form = $form_state = array(); - $form = form_test_validate_required_form($form, $form_state); + $form = array(); + $form = \Drupal::formBuilder()->getForm('Drupal\form_test\Form\FormTestValidateRequiredForm'); // Attempt to submit the form with no required fields set. $edit = array(); @@ -294,8 +294,8 @@ function testCheckboxProcessing() { * Tests validation of #type 'select' elements. */ function testSelect() { - $form = $form_state = array(); - $form = form_test_select($form, $form_state); + $form = array(); + $form = \Drupal::formBuilder()->getForm('Drupal\form_test\Form\TestSelect'); $error = '!name field is required.'; $this->drupalGet('form-test/select'); @@ -367,8 +367,8 @@ function testEmptySelect() { * Tests validation of #type 'number' and 'range' elements. */ function testNumber() { - $form = $form_state = array(); - $form = form_test_number($form, $form_state); + $form = array(); + $form = \Drupal::formBuilder()->getForm('Drupal\form_test\Form\TestNumber'); // Array with all the error messages to be checked. $error_messages = array( diff --git a/core/modules/system/lib/Drupal/system/Tests/Form/ValidationTest.php b/core/modules/system/lib/Drupal/system/Tests/Form/ValidationTest.php index bda5872..41b1e2e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Form/ValidationTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Form/ValidationTest.php @@ -205,8 +205,8 @@ function testPatternValidation() { * @see form_test_validate_required_form() */ function testCustomRequiredError() { - $form = $form_state = array(); - $form = form_test_validate_required_form($form, $form_state); + $form = array(); + $form = \Drupal::formBuilder()->getForm('Drupal\form_test\Form\FormTestValidateRequiredForm'); // Verify that a custom #required error can be set. $edit = array(); 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 bcd8483..4d723ab 100644 --- a/core/modules/system/tests/modules/form_test/form_test.module +++ b/core/modules/system/tests/modules/form_test/form_test.module @@ -40,18 +40,6 @@ function _form_test_submit_values_json($form, &$form_state) { } /** - * Form builder for testing hook_form_alter() and hook_form_FORM_ID_alter(). - * - * @deprecated Use \Drupal\form_test\alterForm() - */ -function form_test_alter_form($form, &$form_state) { - // Elements can be added as needed for future testing needs, but for now, - // we're only testing alter hooks that do not require any elements added by - // this function. - return $form; -} - -/** * Implements hook_form_FORM_ID_alter() on behalf of block.module. */ function block_form_form_test_alter_form_alter(&$form, &$form_state) { @@ -82,272 +70,6 @@ function system_form_form_test_alter_form_alter(&$form, &$form_state) { } /** - * Form builder for testing drupal_validate_form(). - * - * Serves for testing form processing and alterations by form validation - * handlers, especially for the case of a validation error: - * - form_set_value() should be able to alter submitted values in - * $form_state['values'] without affecting the form element. - * - #element_validate handlers should be able to alter the $element in the form - * structure and the alterations should be contained in the rebuilt form. - * - #validate handlers should be able to alter the $form and the alterations - * should be contained in the rebuilt form. - * - * @deprecated Use \Drupal\form_test\validateForm() - */ -function form_test_validate_form($form, &$form_state) { - $object = new Callbacks(); - - $form['name'] = array( - '#type' => 'textfield', - '#title' => 'Name', - '#default_value' => '', - '#element_validate' => array(array($object, 'validateName')), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Save', - ); - - // To simplify this test, enable form caching and use form storage to - // remember our alteration. - $form_state['cache'] = TRUE; - - return $form; -} - -/** - * Form validation handler for form_test_validate_form(). - */ -function form_test_validate_form_validate(&$form, &$form_state) { - if ($form_state['values']['name'] == 'validate') { - // Alter the form element. - $form['name']['#value'] = '#value changed by #validate'; - // Alter the submitted value in $form_state. - form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state); - // Output the element's value from $form_state. - drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name']))); - - // Trigger a form validation error to see our changes. - form_set_error('', $form_state); - } -} - -/** - * Form constructor to test the #required property. - * - * @deprecated Use \Drupal\form_test\validateRequiredForm() - */ -function form_test_validate_required_form($form, &$form_state) { - $options = drupal_map_assoc(array('foo', 'bar')); - $validate = array('form_test_validate_required_form_element_validate'); - - $form['textfield'] = array( - '#type' => 'textfield', - '#title' => 'Name', - '#required' => TRUE, - '#required_error' => t('Please enter a name.'), - ); - $form['checkboxes'] = array( - '#type' => 'checkboxes', - '#title' => 'Checkboxes', - '#options' => $options, - '#required' => TRUE, - '#form_test_required_error' => t('Please choose at least one option.'), - '#element_validate' => $validate, - ); - $form['select'] = array( - '#type' => 'select', - '#title' => 'Select', - '#options' => $options, - '#required' => TRUE, - '#form_test_required_error' => t('Please select something.'), - '#element_validate' => $validate, - ); - $form['radios'] = array( - '#type' => 'radios', - '#title' => 'Radios', - '#options' => $options, - '#required' => TRUE, - ); - $form['radios_optional'] = array( - '#type' => 'radios', - '#title' => 'Radios (optional)', - '#options' => $options, - ); - $form['radios_optional_default_value_false'] = array( - '#type' => 'radios', - '#title' => 'Radios (optional, with a default value of FALSE)', - '#options' => $options, - '#default_value' => FALSE, - ); - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit'); - return $form; -} - -/** - * Form element validation handler for 'Name' field in form_test_validate_required_form(). - */ -function form_test_validate_required_form_element_validate($element, &$form_state) { - // Set a custom validation error on the #required element. - if (!empty($element['#required_but_empty']) && isset($element['#form_test_required_error'])) { - form_error($element, $form_state, $element['#form_test_required_error']); - } -} - -/** - * Form submission handler for form_test_validate_required_form(). - */ -function form_test_validate_required_form_submit($form, &$form_state) { - drupal_set_message('The form_test_validate_required_form form was submitted successfully.'); -} - -/** - * Form constructor to test the #required property without #title. - * - * @deprecated Use \Drupal\form_test\validateRequiredFormNoTitle() - */ -function form_test_validate_required_form_no_title($form, &$form_state) { - $form['textfield'] = array( - '#type' => 'textfield', - '#required' => TRUE, - ); - $form['actions'] = array('#type' => 'actions'); - $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit'); - return $form; -} - -/** - * Form submission handler for form_test_validate_required_form_no_title(). - */ -function form_test_validate_required_form_no_title_submit($form, &$form_state) { - drupal_set_message('The form_test_validate_required_form_no_title form was submitted successfully.'); -} - -/** - * Builds a simple form with a button triggering partial validation. - * - * @deprecated Use \Drupal\form_test\validateFormWithErrorSuppression() - */ -function form_test_limit_validation_errors_form($form, &$form_state) { - $form['title'] = array( - '#type' => 'textfield', - '#title' => 'Title', - '#required' => TRUE, - ); - - $form['test'] = array( - '#title' => 'Test', - '#type' => 'textfield', - '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'), - ); - $form['test_numeric_index'] = array( - '#tree' => TRUE, - ); - $form['test_numeric_index'][0] = array( - '#title' => 'Test (numeric index)', - '#type' => 'textfield', - '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'), - ); - - $form['test_substring'] = array( - '#tree' => TRUE, - ); - $form['test_substring']['foo'] = array( - '#title' => 'Test (substring) foo', - '#type' => 'textfield', - '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'), - ); - $form['test_substring']['foobar'] = array( - '#title' => 'Test (substring) foobar', - '#type' => 'textfield', - '#element_validate' => array('form_test_limit_validation_errors_element_validate_test'), - ); - - $form['actions']['partial'] = array( - '#type' => 'submit', - '#limit_validation_errors' => array(array('test')), - '#submit' => array('form_test_limit_validation_errors_form_partial_submit'), - '#value' => t('Partial validate'), - ); - $form['actions']['partial_numeric_index'] = array( - '#type' => 'submit', - '#limit_validation_errors' => array(array('test_numeric_index', 0)), - '#submit' => array('form_test_limit_validation_errors_form_partial_submit'), - '#value' => t('Partial validate (numeric index)'), - ); - $form['actions']['substring'] = array( - '#type' => 'submit', - '#limit_validation_errors' => array(array('test_substring', 'foo')), - '#submit' => array('form_test_limit_validation_errors_form_partial_submit'), - '#value' => t('Partial validate (substring)'), - ); - $form['actions']['full'] = array( - '#type' => 'submit', - '#value' => t('Full validate'), - ); - return $form; -} - -/** - * Form element validation handler for the 'test' element. - */ -function form_test_limit_validation_errors_element_validate_test(&$element, &$form_state) { - if ($element['#value'] == 'invalid') { - form_error($element, $form_state, t('@label element is invalid', array('@label' => $element['#title']))); - } -} - -/** - * Form submit handler for the partial validation submit button. - */ -function form_test_limit_validation_errors_form_partial_submit($form, $form_state) { - // The title has not been validated, thus its value - in case of the test case - // an empty string - may not be set. - if (!isset($form_state['values']['title']) && isset($form_state['values']['test'])) { - drupal_set_message('Only validated values appear in the form values.'); - } -} - -/** - * Builds a simple form using the FAPI #pattern proterty. - * - * @deprecated Use \Drupal\form_test\validatePattern() - */ -function form_test_pattern_form($form, &$form_state) { - $form['textfield'] = array( - '#type' => 'textfield', - '#title' => 'One digit followed by lowercase letters', - '#pattern' => '[0-9][a-z]+', - ); - $form['tel'] = array( - '#type' => 'tel', - '#title' => 'Everything except numbers', - '#pattern' => '[^\d]*', - ); - $form['password'] = array( - '#type' => 'password', - '#title' => 'Password', - '#pattern' => '[01]+', - ); - $form['url'] = array( - '#type' => 'url', - '#title' => 'Client side validation', - '#decription' => 'Just client side validation, using the #pattern attribute.', - '#attributes' => array( - 'pattern' => '.*foo.*', - ), - '#pattern' => 'ignored', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** * Create a header and options array. Helper function for callbacks. */ function _form_test_tableselect_get_data() { @@ -546,111 +268,6 @@ function _form_test_vertical_tabs_form($form, &$form_state) { } /** - * A multistep form for testing the form storage. - * - * It uses two steps for editing a virtual "thing". Any changes to it are saved - * in the form storage and have to be present during any step. By setting the - * request parameter "cache" the form can be tested with caching enabled, as - * it would be the case, if the form would contain some #ajax callbacks. - * - * @see form_test_storage_form_submit() - * - * @deprecated Use \Drupal\form_test\testStorage() - */ -function form_test_storage_form($form, &$form_state) { - if ($form_state['rebuild']) { - $form_state['input'] = array(); - } - // Initialize - if (empty($form_state['storage'])) { - if (empty($form_state['input'])) { - $_SESSION['constructions'] = 0; - } - // Put the initial thing into the storage - $form_state['storage'] = array( - 'thing' => array( - 'title' => 'none', - 'value' => '', - ), - ); - } - // Count how often the form is constructed. - $_SESSION['constructions']++; - drupal_set_message("Form constructions: " . $_SESSION['constructions']); - - $form['title'] = array( - '#type' => 'textfield', - '#title' => 'Title', - '#default_value' => $form_state['storage']['thing']['title'], - '#required' => TRUE, - ); - $form['value'] = array( - '#type' => 'textfield', - '#title' => 'Value', - '#default_value' => $form_state['storage']['thing']['value'], - '#element_validate' => array('form_test_storage_element_validate_value_cached'), - ); - $form['continue_button'] = array( - '#type' => 'button', - '#value' => 'Reset', - // Rebuilds the form without keeping the values. - ); - $form['continue_submit'] = array( - '#type' => 'submit', - '#value' => 'Continue submit', - '#submit' => array('form_storage_test_form_continue_submit'), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Save', - ); - - if (isset($_REQUEST['cache'])) { - // Manually activate caching, so we can test that the storage keeps working - // when it's enabled. - $form_state['cache'] = TRUE; - } - - return $form; -} - -/** - * Form element validation handler for 'value' element in form_test_storage_form(). - * - * Tests updating of cached form storage during validation. - */ -function form_test_storage_element_validate_value_cached($element, &$form_state) { - // If caching is enabled and we receive a certain value, change the storage. - // This presumes that another submitted form value triggers a validation error - // elsewhere in the form. Form API should still update the cached form storage - // though. - if (isset($_REQUEST['cache']) && $form_state['values']['value'] == 'change_title') { - $form_state['storage']['thing']['changed'] = TRUE; - } -} - -/** - * Form submit handler to continue multi-step form. - */ -function form_storage_test_form_continue_submit($form, &$form_state) { - $form_state['storage']['thing']['title'] = $form_state['values']['title']; - $form_state['storage']['thing']['value'] = $form_state['values']['value']; - $form_state['rebuild'] = TRUE; -} - -/** - * Form submit handler to finish multi-step form. - */ -function form_test_storage_form_submit($form, &$form_state) { - drupal_set_message("Title: " . check_plain($form_state['values']['title'])); - drupal_set_message("Form constructions: " . $_SESSION['constructions']); - if (isset($form_state['storage']['thing']['changed'])) { - drupal_set_message("The thing has been changed."); - } - $form_state['redirect_route']['route_name'] = ''; -} - -/** * A form for testing form labels and required marks. * * @deprecated Use \Drupal\form_test\testLabel() @@ -750,668 +367,97 @@ function form_label_test_form() { function form_test_wrapper_callback($form_id) { $form_state = array( 'build_info' => array('args' => array()), - 'wrapper_callback' => 'form_test_wrapper_callback_wrapper', - ); - return drupal_build_form($form_id, $form_state); -} - -/** - * Form wrapper for form_test_wrapper_callback_form(). - */ -function form_test_wrapper_callback_wrapper($form, &$form_state) { - $form['wrapper'] = array('#markup' => 'Form wrapper callback element output.'); - return $form; -} - -/** - * Form builder for form wrapper callback test. - * - * @deprecated Use \Drupal\form_test\testWrapperCallback() - */ -function form_test_wrapper_callback_form($form, &$form_state) { - $form['builder'] = array('#markup' => 'Form builder element output.'); - return $form; -} - -/** - * Form builder for form_state_values_clean() test. - * - * @deprecated Use \Drupal\form_test\testFormStateClean() - */ -function form_test_form_state_values_clean_form($form, &$form_state) { - // Build an example form containing multiple submit and button elements; not - // only on the top-level. - $form = array('#tree' => TRUE); - $form['foo'] = array('#type' => 'submit', '#value' => t('Submit')); - $form['bar'] = array('#type' => 'submit', '#value' => t('Submit')); - $form['beer'] = array('#type' => 'value', '#value' => 1000); - $form['baz']['foo'] = array('#type' => 'button', '#value' => t('Submit')); - $form['baz']['baz'] = array('#type' => 'submit', '#value' => t('Submit')); - $form['baz']['beer'] = array('#type' => 'value', '#value' => 2000); - return $form; -} - -/** - * Form submit handler for form_state_values_clean() test form. - */ -function form_test_form_state_values_clean_form_submit($form, &$form_state) { - form_state_values_clean($form_state); - // This won't have a proper JSON header, but Drupal doesn't check for that - // anyway so this is fine until it's replaced with a JsonResponse. - print drupal_json_encode($form_state['values']); - exit; -} - -/** - * Form constructor for the form_state_values_clean() test. - * - * @deprecated Use \Drupal\form_test\testFormStateCleanAdvanced() - */ -function form_test_form_state_values_clean_advanced_form($form, &$form_state) { - // Build an example form containing a managed file and a submit form element. - $form['image'] = array( - '#type' => 'managed_file', - '#title' => t('Image'), - '#upload_location' => 'public://', - '#default_value' => 0, - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - return $form; -} - -/** - * Form submission handler for form_test_form_state_values_clean_advanced_form(). - */ -function form_test_form_state_values_clean_advanced_form_submit($form, &$form_state) { - form_state_values_clean($form_state); - print t('You WIN!'); - exit; -} - -/** - * 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() - */ -function form_test_select($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - - $base = array( - '#type' => 'select', - '#options' => drupal_map_assoc(array('one', 'two', 'three')), - ); - - $form['select'] = $base + array( - '#title' => '#default_value one', - '#default_value' => 'one', - ); - $form['select_required'] = $base + array( - '#title' => '#default_value one, #required', - '#required' => TRUE, - '#default_value' => 'one', - ); - $form['select_optional'] = $base + array( - '#title' => '#default_value one, not #required', - '#required' => FALSE, - '#default_value' => 'one', - ); - $form['empty_value'] = $base + array( - '#title' => '#default_value one, #required, #empty_value 0', - '#required' => TRUE, - '#default_value' => 'one', - '#empty_value' => 0, - ); - $form['empty_value_one'] = $base + array( - '#title' => '#default_value = #empty_value, #required', - '#required' => TRUE, - '#default_value' => 'one', - '#empty_value' => 'one', - ); - - $form['no_default'] = $base + array( - '#title' => 'No #default_value, #required', - '#required' => TRUE, - ); - $form['no_default_optional'] = $base + array( - '#title' => 'No #default_value, not #required', - '#required' => FALSE, - '#description' => 'Should result in "one" because it is not required and there is no #empty_value requested, so default browser behavior of preselecting first option is in effect.', - ); - $form['no_default_optional_empty_value'] = $base + array( - '#title' => 'No #default_value, not #required, #empty_value empty string', - '#empty_value' => '', - '#required' => FALSE, - '#description' => 'Should result in an empty string (due to #empty_value) because it is optional.', - ); - - $form['no_default_empty_option'] = $base + array( - '#title' => 'No #default_value, #required, #empty_option', - '#required' => TRUE, - '#empty_option' => '- Choose -', - ); - $form['no_default_empty_option_optional'] = $base + array( - '#title' => 'No #default_value, not #required, #empty_option', - '#empty_option' => '- Dismiss -', - '#description' => 'Should result in an empty string (default of #empty_value) because it is optional.', - ); - - $form['no_default_empty_value'] = $base + array( - '#title' => 'No #default_value, #required, #empty_value 0', - '#required' => TRUE, - '#empty_value' => 0, - '#description' => 'Should never result in 0.', - ); - $form['no_default_empty_value_one'] = $base + array( - '#title' => 'No #default_value, #required, #empty_value one', - '#required' => TRUE, - '#empty_value' => 'one', - '#description' => 'A mistakenly assigned #empty_value contained in #options should not be valid.', - ); - $form['no_default_empty_value_optional'] = $base + array( - '#title' => 'No #default_value, not #required, #empty_value 0', - '#required' => FALSE, - '#empty_value' => 0, - '#description' => 'Should result in 0 because it is optional.', - ); - - $form['multiple'] = $base + array( - '#title' => '#multiple, #default_value two', - '#default_value' => array('two'), - '#multiple' => TRUE, - ); - $form['multiple_no_default'] = $base + array( - '#title' => '#multiple, no #default_value', - '#multiple' => TRUE, - ); - $form['multiple_no_default_required'] = $base + array( - '#title' => '#multiple, #required, no #default_value', - '#required' => TRUE, - '#multiple' => TRUE, - ); - - $form['submit'] = array('#type' => 'submit', '#value' => 'Submit'); - return $form; -} - -/** - * Builds a form to test select elements when #options is not an array. - * - * @deprecated Use \Drupal\form_test\testEmptySelect() - */ -function form_test_empty_select($form, &$form_state) { - $form['empty_select'] = array( - '#type' => 'select', - '#title' => t('Empty Select'), - '#multiple' => FALSE, - '#options' => NULL, - ); - return $form; -} - -/** - * Builds a form to test the language select form element. - * - * @deprecated Use \Drupal\form_test\testLanguageSelect() - */ -function form_test_language_select() { - $form['#submit'] = array('_form_test_submit_values_json'); - - $form['languages_all'] = array( - '#title' => t('Languages: All'), - '#type' => 'language_select', - '#languages' => Language::STATE_ALL, - '#default_value' => 'xx', - ); - $form['languages_configurable'] = array( - '#title' => t('Languages: Configurable'), - '#type' => 'language_select', - '#languages' => Language::STATE_CONFIGURABLE, - '#default_value' => 'en', - ); - $form['languages_locked'] = array( - '#title' => t('Languages: Locked'), - '#type' => 'language_select', - '#languages' => Language::STATE_LOCKED, - ); - $form['languages_config_and_locked'] = array( - '#title' => t('Languages: Configurable and locked'), - '#type' => 'language_select', - '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, - '#default_value' => 'dummy_value', - ); - $form['language_custom_options'] = array( - '#title' => t('Languages: Custom'), - '#type' => 'language_select', - '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, - '#options' => array('opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'), - '#default_value' => 'opt2', - ); - - $form['submit'] = array('#type' => 'submit', '#value' => 'Submit'); - return $form; -} - -/** - * Builds a form to test #type 'number' and 'range' validation. - * - * @param $element - * The element type to test. Can be 'number' or 'range'. Defaults to 'number'. - * - * @deprecated Use \Drupal\form_test\testNumber() - * - * @deprecated Use \Drupal\form_test\testNumberRange() - */ -function form_test_number($form, &$form_state, $element = 'number') { - $base = array( - '#type' => $element, - ); - - $form['integer_no_number'] = $base + array( - '#title' => 'Integer test, #no_error', - '#default_value' => '#no_number', - ); - $form['integer_no_step'] = $base + array( - '#title' => 'Integer test without step', - '#default_value' => 5, - ); - $form['integer_no_step_step_error'] = $base + array( - '#title' => 'Integer test without step, #step_error', - '#default_value' => 4.5, - ); - $form['integer_step'] = $base + array( - '#title' => 'Integer test with step', - '#default_value' => 5, - '#step' => 1, - ); - $form['integer_step_error'] = $base + array( - '#title' => 'Integer test, with step, #step_error', - '#default_value' => 5, - '#step' => 2, - ); - $form['integer_step_min'] = $base + array( - '#title' => 'Integer test with min value', - '#default_value' => 5, - '#min' => 0, - '#step' => 1, - ); - $form['integer_step_min_error'] = $base + array( - '#title' => 'Integer test with min value, #min_error', - '#default_value' => 5, - '#min' => 6, - '#step' => 1, - ); - $form['integer_step_max'] = $base + array( - '#title' => 'Integer test with max value', - '#default_value' => 5, - '#max' => 6, - '#step' => 1, - ); - $form['integer_step_max_error'] = $base + array( - '#title' => 'Integer test with max value, #max_error', - '#default_value' => 5, - '#max' => 4, - '#step' => 1, - ); - $form['integer_step_min_border'] = $base + array( - '#title' => 'Integer test with min border check', - '#default_value' => -1, - '#min' => -1, - '#step' => 1, - ); - $form['integer_step_max_border'] = $base + array( - '#title' => 'Integer test with max border check', - '#default_value' => 5, - '#max' => 5, - '#step' => 1, - ); - $form['integer_step_based_on_min'] = $base + array( - '#title' => 'Integer test with step based on min check', - '#default_value' => 3, - '#min' => -1, - '#step' => 2, - ); - $form['integer_step_based_on_min_error'] = $base + array( - '#title' => 'Integer test with step based on min check, #step_error', - '#default_value' => 4, - '#min' => -1, - '#step' => 2, - ); - $form['float_small_step'] = $base + array( - '#title' => 'Float test with a small step', - '#default_value' => 4, - '#step' => 0.0000000000001, - ); - $form['float_step_no_error'] = $base + array( - '#title' => 'Float test', - '#default_value' => 1.2, - '#step' => 0.3, - ); - $form['float_step_error'] = $base + array( - '#title' => 'Float test, #step_error', - '#default_value' => 1.3, - '#step' => 0.3, - ); - $form['float_step_hard_no_error'] = $base + array( - '#title' => 'Float test hard', - '#default_value' => 0.9411764729088, - '#step' => 0.00392156863712, - ); - $form['float_step_hard_error'] = $base + array( - '#title' => 'Float test hard, #step_error', - '#default_value' => 0.9411764, - '#step' => 0.00392156863, - ); - $form['float_step_any_no_error'] = $base + array( - '#title' => 'Arbitrary float', - '#default_value' => 0.839562930284, - '#step' => 'aNy', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** - * Form constructor for testing #type 'range' elements. - * - * @see form_test_range_submit() - * @ingroup forms - * - * @deprecated Use \Drupal\form_test\testRange() - */ -function form_test_range($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - - $form['with_default_value'] = array( - '#type' => 'range', - '#title' => 'Range with default value', - '#min' => 10, - '#max' => 20, - '#step' => 2, - '#default_value' => 18, - '#description' => 'The default value is 18.', - ); - $form['float'] = array( - '#type' => 'range', - '#title' => 'Float', - '#min' => 10, - '#max' => 11, - '#step' => 'any', - '#description' => 'Floating point number between 10 and 11.', - ); - $form['integer'] = array( - '#type' => 'range', - '#title' => 'Integer', - '#min' => 2, - '#max' => 8, - '#step' => 2, - '#description' => 'Even integer between 2 and 8.', - ); - $form['offset'] = array( - '#type' => 'range', - '#title' => 'Offset', - '#min' => 2.9, - '#max' => 10.9, - '#description' => 'Value between 2.9 and 10.9.', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** - * Form constructor for testing invalid #type 'range' elements. - * - * @ingroup forms - * - * @deprecated Use \Drupal\form_test\testRangeInvalid() - */ -function form_test_range_invalid($form, &$form_state) { - $form['minmax'] = array( - '#type' => 'range', - '#min' => 10, - '#max' => 5, - '#title' => 'Invalid range', - '#description' => 'Minimum greater than maximum.', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** - * Form constructor for testing #type 'color' elements. - * - * @see form_test_color_submit() - * @ingroup forms - * - * @deprecated Use \Drupal\form_test\testColor() - */ -function form_test_color($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - - $form['color'] = array( - '#type' => 'color', - '#title' => 'Color', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; -} - -/** - * Builds a form to test the placeholder attribute. - * - * @deprecated Use \Drupal\form_test\testPlaceholder() - */ -function form_test_placeholder_test($form, &$form_state) { - foreach (array('textfield', 'textarea', 'url', 'password', 'search', 'tel', 'email', 'number') as $type) { - $form[$type] = array( - '#type' => $type, - '#title' => $type, - '#placeholder' => 'placeholder-text', - ); - } - - return $form; -} - -/** - * Form constructor to test expansion of #type checkboxes and radios. - * - * @deprecated Use \Drupal\form_test\testCheckboxesRadios() - */ -function form_test_checkboxes_radios($form, &$form_state, $customize = FALSE) { - $form['#submit'] = array('_form_test_submit_values_json'); - - // Expand #type checkboxes, setting custom element properties for some but not - // all options. - $form['checkboxes'] = array( - '#type' => 'checkboxes', - '#title' => 'Checkboxes', - '#options' => array( - 0 => 'Zero', - 'foo' => 'Foo', - 1 => 'One', - 'bar' => 'Bar', - '>' => 'Special Char', - ), - ); - if ($customize) { - $form['checkboxes'] += array( - 'foo' => array( - '#description' => 'Enable to foo.', - ), - 1 => array( - '#weight' => 10, - ), - ); - } - - // Expand #type radios, setting custom element properties for some but not - // all options. - $form['radios'] = array( - '#type' => 'radios', - '#title' => 'Radios', - '#options' => array( - 0 => 'Zero', - 'foo' => 'Foo', - 1 => 'One', - 'bar' => 'Bar', - '>' => 'Special Char', - ), + 'wrapper_callback' => 'form_test_wrapper_callback_wrapper', ); - if ($customize) { - $form['radios'] += array( - 'foo' => array( - '#description' => 'Enable to foo.', - ), - 1 => array( - '#weight' => 10, - ), - ); - } - - $form['submit'] = array('#type' => 'submit', '#value' => 'Submit'); + return drupal_build_form($form_id, $form_state); +} +/** + * Form wrapper for form_test_wrapper_callback_form(). + */ +function form_test_wrapper_callback_wrapper($form, &$form_state) { + $form['wrapper'] = array('#markup' => 'Form wrapper callback element output.'); return $form; } /** - * Form constructor for testing #type 'email' elements. - * - * @see form_test_email_submit() - * @ingroup forms + * Form builder for form wrapper callback test. * - * @deprecated Use \Drupal\form_test\testEmail() + * @deprecated Use \Drupal\form_test\testWrapperCallback() */ -function form_test_email($form, &$form_state) { - $form['#submit'] = array('_form_test_submit_values_json'); - $form['email'] = array( - '#type' => 'email', - '#title' => 'E-Mail address', - '#description' => 'An e-mail address.', - ); - $form['email_required'] = array( - '#type' => 'email', - '#title' => 'Address', - '#required' => TRUE, - '#description' => 'A required e-mail address field.', - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); +function form_test_wrapper_callback_form($form, &$form_state) { + $form['builder'] = array('#markup' => 'Form builder element output.'); return $form; } /** - * Form constructor for testing #type 'url' elements. - * - * @see form_test_url_submit() - * @ingroup forms + * Build a form to test a checkbox. * - * @deprecated Use \Drupal\form_test\testUrl() + * @deprecated Use \Drupal\form_test\testCheckbox() */ -function form_test_url($form, &$form_state) { +function _form_test_checkbox($form, &$form_state) { $form['#submit'] = array('_form_test_submit_values_json'); - $form['url'] = array( - '#type' => 'url', - '#title' => 'Optional URL', - '#description' => 'An optional URL field.', - ); - $form['url_required'] = array( - '#type' => 'url', - '#title' => 'Required URL', - '#description' => 'A required URL field.', + + // 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' => 'Submit', + '#value' => t('Submit') ); + return $form; } @@ -1722,37 +768,6 @@ function form_test_form_rebuild_preserve_values_form_submit($form, &$form_state) } /** - * Form constructor for testing form state persistence. - * - * @deprecated Use \Drupal\form_test\testStatePersistence() - */ -function form_test_state_persist($form, &$form_state) { - $form['title'] = array( - '#type' => 'textfield', - '#title' => 'title', - '#default_value' => 'DEFAULT', - '#required' => TRUE, - ); - $form_state['value'] = 'State persisted.'; - - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - return $form; -} - -/** - * Submit handler. - * - * @see form_test_state_persist() - */ -function form_test_state_persist_submit($form, &$form_state) { - drupal_set_message($form_state['value']); - $form_state['rebuild'] = TRUE; -} - -/** * Implements hook_form_FORM_ID_alter(). * * @see form_test_state_persist() @@ -1845,125 +860,6 @@ function form_test_programmatic_form_submit($form, &$form_state) { } /** - * Form builder to test button click detection. - * - * @deprecated Use \Drupal\form_test\testClickedButton() - */ -function form_test_clicked_button($form, &$form_state, $first, $second, $third) { - // A single text field. In IE, when a form has only one non-button input field - // and the ENTER key is pressed while that field has focus, the form is - // submitted without any information identifying the button responsible for - // the submission. In other browsers, the form is submitted as though the - // first button were clicked. - $form['text'] = array( - '#title' => 'Text', - '#type' => 'textfield', - ); - - // Loop through each path argument, addding buttons based on the information - // in the argument. For example, if the path is - // form-test/clicked-button/s/i/rb, then 3 buttons are added: a 'submit', an - // 'image_button', and a 'button' with #access=FALSE. This enables form.test - // to test a variety of combinations. - $i=0; - $args = array($first, $second, $third); - foreach ($args as $arg) { - $name = 'button' . ++$i; - // 's', 'b', or 'i' in the argument define the button type wanted. - if (strpos($arg, 's') !== FALSE) { - $type = 'submit'; - } - elseif (strpos($arg, 'b') !== FALSE) { - $type = 'button'; - } - elseif (strpos($arg, 'i') !== FALSE) { - $type = 'image_button'; - } - else { - $type = NULL; - } - if (isset($type)) { - $form[$name] = array( - '#type' => $type, - '#name' => $name, - ); - // Image buttons need a #src; the others need a #value. - if ($type == 'image_button') { - $form[$name]['#src'] = 'core/misc/druplicon.png'; - } - else { - $form[$name]['#value'] = $name; - } - // 'r' for restricted, so we can test that button click detection code - // correctly takes #access security into account. - if (strpos($arg, 'r') !== FALSE) { - $form[$name]['#access'] = FALSE; - } - } - } - - return $form; -} - -/** - * Form validation handler for the form_test_clicked_button() form. - */ -function form_test_clicked_button_validate($form, &$form_state) { - if (isset($form_state['triggering_element'])) { - drupal_set_message(t('The clicked button is %name.', array('%name' => $form_state['triggering_element']['#name']))); - } - else { - drupal_set_message('There is no clicked button.'); - } -} - -/** - * Form submit handler for the form_test_clicked_button() form. - */ -function form_test_clicked_button_submit($form, &$form_state) { - drupal_set_message('Submit handler for form_test_clicked_button executed.'); -} - -/** - * Form builder to detect form redirect. - * - * @deprecated Use \Drupal\form_test\testRedirect() - */ -function form_test_redirect($form, &$form_state) { - $form['redirection'] = array( - '#type' => 'checkbox', - '#title' => t('Use redirection'), - ); - $form['destination'] = array( - '#type' => 'textfield', - '#title' => t('Redirect destination'), - '#states' => array( - 'visible' => array( - ':input[name="redirection"]' => array('checked' => TRUE), - ), - ), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => t('Submit'), - ); - - return $form; -} - -/** - * Form submit handler to test different redirect behaviours. - */ -function form_test_redirect_submit(&$form, &$form_state) { - if (!empty($form_state['values']['redirection'])) { - $form_state['redirect'] = !empty($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL; - } - else { - $form_state['redirect'] = FALSE; - } -} - -/** * Implements hook_form_FORM_ID_alter() for the registration form. */ function form_test_form_user_register_form_alter(&$form, &$form_state) { @@ -2000,63 +896,6 @@ function form_test_checkbox_type_juggling($form, $form_state, $default_value, $r } /** - * Tests checkboxes zero. - * - * @deprecated Use \Drupal\form_test\testCheckboxesZero() - */ -function form_test_checkboxes_zero($form, &$form_state, $json = TRUE) { - $form['checkbox_off'] = array( - '#title' => t('Checkbox off'), - '#type' => 'checkboxes', - '#options' => array('foo', 'bar', 'baz'), - ); - $form['checkbox_zero_default'] = array( - '#title' => t('Zero default'), - '#type' => 'checkboxes', - '#options' => array('foo', 'bar', 'baz'), - '#default_value' => array(0), - ); - $form['checkbox_string_zero_default'] = array( - '#title' => t('Zero default (string)'), - '#type' => 'checkboxes', - '#options' => array('foo', 'bar', 'baz'), - '#default_value' => array('0'), - ); - $form['submit'] = array( - '#type' => 'submit', - '#value' => 'Save', - ); - if ($json) { - $form['#submit'][] = '_form_test_submit_values_json'; - } - else { - $form['#submit'][] = '_form_test_checkboxes_zero_no_redirect'; - } - return $form; -} - -function _form_test_checkboxes_zero_no_redirect($form, &$form_state) { - $form_state['redirect'] = FALSE; -} - -/** - * Builds a form to test the required attribute. - * - * @deprecated Use \Drupal\form_test\testRequired() - */ -function form_test_required_attribute($form, &$form_state) { - foreach (array('textfield', 'textarea', 'password') as $type) { - $form[$type] = array( - '#type' => $type, - '#required' => TRUE, - '#title' => $type, - ); - } - - return $form; -} - -/** * Menu callback returns two instances of the same form. * * @deprecated \Drupal\form_test\Controller\FormTestController::doubleForm() @@ -2084,119 +923,6 @@ function form_test_html_id($form, &$form_state) { return $form; } -/** - * Builds a simple form to test form button classes. - * - * @deprecated Use \Drupal\form_test\testButtonClass() - */ -function form_test_button_class($form, &$form_state) { - $form['button'] = array( - '#type' => 'button', - '#value' => 'test', - '#button_type' => 'foo', - ); - $form['delete'] = array( - '#type' => 'button', - '#value' => 'Delete', - '#button_type' => 'danger', - ); - return $form; -} - -/** - * Builds a simple form to test the #group property on #type 'details'. - * - * @deprecated Use \Drupal\form_test\testGroupDetails() - */ -function form_test_group_details() { - $form['details'] = array( - '#type' => 'details', - '#title' => 'Root element', - ); - $form['meta'] = array( - '#type' => 'details', - '#title' => 'Group element', - '#group' => 'details', - ); - $form['meta']['element'] = array( - '#type' => 'textfield', - '#title' => 'Nest in details element', - ); - return $form; -} - -/** - * Builds a simple form to test the #group property on #type 'container'. - * - * @deprecated Use \Drupal\form_test\testGroupContainer() - */ -function form_test_group_container() { - $form['container'] = array( - '#type' => 'container', - ); - $form['meta'] = array( - '#type' => 'details', - '#title' => 'Group element', - '#group' => 'container', - ); - $form['meta']['element'] = array( - '#type' => 'textfield', - '#title' => 'Nest in details element', - ); - return $form; -} - -/** - * Builds a simple form to test the #group property on #type 'fieldset'. - * - * @deprecated Use \Drupal\form_test\testGroupFieldset() - */ -function form_test_group_fieldset() { - $form['fieldset'] = array( - '#type' => 'fieldset', - '#title' => 'Fieldset', - ); - $form['meta'] = array( - '#type' => 'container', - '#title' => 'Group element', - '#group' => 'fieldset', - ); - $form['meta']['element'] = array( - '#type' => 'textfield', - '#title' => 'Nest in container element', - ); - return $form; -} - -/** - * Builds a simple form to test the #group property on #type 'vertical_tabs'. - * - * @deprecated Use \Drupal\form_test\testGroupVerticalTabs() - */ -function form_test_group_vertical_tabs() { - $form['vertical_tabs'] = array( - '#type' => 'vertical_tabs', - ); - $form['meta'] = array( - '#type' => 'details', - '#title' => 'First group element', - '#group' => 'vertical_tabs', - ); - $form['meta']['element'] = array( - '#type' => 'textfield', - '#title' => 'First nested element in details element', - ); - $form['meta_2'] = array( - '#type' => 'details', - '#title' => 'Second group element', - '#group' => 'vertical_tabs', - ); - $form['meta_2']['element_2'] = array( - '#type' => 'textfield', - '#title' => 'Second nested element in details element', - ); - return $form; -} /** * Builds a form which gets the database connection stored in the form state. 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 f8467ff..1a0857b 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 @@ -36,21 +36,21 @@ form_test.route5: form_test.route6: path: '/form-test/confirm-form' defaults: - _form: '\Drupal\form_test\ConfirmFormTestForm' + _form: '\Drupal\form_test\Form\ConfirmFormTestForm' requirements: _access: 'TRUE' form_test.route7: path: '/form-test/confirm-form-array-path' defaults: - _form: '\Drupal\form_test\ConfirmFormArrayPathTestForm' + _form: '\Drupal\form_test\Form\ConfirmFormArrayPathTestForm' requirements: _access: 'TRUE' form_test.route8: path: '/form-test/autocomplete' defaults: - _form: '\Drupal\form_test\FormTestAutocompleteForm' + _form: '\Drupal\form_test\Form\FormTestAutocompleteForm' requirements: _access: 'TRUE' @@ -88,7 +88,7 @@ form_test.double_form: form_test.alter_form: path: '/form-test/alter' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::alterForm' + _form: '\Drupal\form_test\Form\FormTestAlterForm' _title: 'Form altering test' requirements: _access: 'TRUE' @@ -96,7 +96,7 @@ form_test.alter_form: form_test.validate_form: path: '/form-test/validate' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::validateForm' + _form: '\Drupal\form_test\Form\FormTestValidateForm' _title: 'Form validation handlers test' requirements: _access: 'TRUE' @@ -104,7 +104,7 @@ form_test.validate_form: form_test.validate_required: path: '/form-test/validate-required' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::validateRequiredForm' + _form: '\Drupal\form_test\Form\FormTestValidateRequiredForm' _title: 'Form #required validation' requirements: _access: 'TRUE' @@ -112,7 +112,7 @@ form_test.validate_required: form_test.validate_required_no_title: path: '/form-test/validate-required-no-title' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::validateRequiredFormNoTitle' + _form: '\Drupal\form_test\Form\FormTestValidateRequiredFormNoTitle' _title: 'Form #required validation without #title' requirements: _access: 'TRUE' @@ -120,7 +120,7 @@ form_test.validate_required_no_title: form_test.validate_with_error_suppresion: path: '/form-test/limit-validation-errors' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::validateFormWithErrorSuppression' + _form: '\Drupal\form_test\Form\FormTestLimitValidationErrorsForm' _title: 'Form validation with some error suppression' requirements: _access: 'TRUE' @@ -128,7 +128,7 @@ form_test.validate_with_error_suppresion: form_test.pattern: path: '/form-test/pattern' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::validatePattern' + _form: '\Drupal\form_test\Form\FormTestPatternForm' _title: 'Pattern validation' requirements: _access: 'TRUE' @@ -170,6 +170,7 @@ form_test.tableselect_js: defaults: _content: '\Drupal\form_test\Form\FormTestForm::testTableSelectJS' _title: 'Tableselect js_select tests' + test_action: NULL requirements: _access: 'TRUE' @@ -184,7 +185,7 @@ form_test.vertical_tabs: form_test.storage: path: '/form_test/form-storage' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testStorage' + _form: '\Drupal\form_test\Form\TestStorage' _title: 'Form storage test' requirements: _access: 'TRUE' @@ -192,7 +193,7 @@ form_test.storage: form_test.state_clean: path: '/form_test/form-state-values-clean' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testFormStateClean' + _form: '\Drupal\form_test\Form\TestFormStateClean' _title: 'Form state values clearance test' requirements: _access: 'TRUE' @@ -200,7 +201,7 @@ form_test.state_clean: form_test.state_clean_advanced: path: '/form_test/form-state-values-clean-advanced' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testFormStateCleanAdvanced' + _form: '\Drupal\form_test\Form\TestFormStateCleanAdvanced' _title: 'Form state values clearance advanced test' requirements: _access: 'TRUE' @@ -216,7 +217,7 @@ form_test.checkbox: form_test.select: path: '/form-test/select' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testSelect' + _form: '\Drupal\form_test\Form\TestSelect' _title: 'Select' requirements: _access: 'TRUE' @@ -224,7 +225,7 @@ form_test.select: form_test.empty_select: path: '/form-test/empty-select' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testEmptySelect' + _form: '\Drupal\form_test\Form\FormTestEmptySelect' _title: 'Empty Select Element' requirements: _access: 'TRUE' @@ -232,7 +233,7 @@ form_test.empty_select: form_test.language_select: path: '/form-test/language_select' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testLanguageSelect' + _form: '\Drupal\form_test\Form\TestLanguageSelect' _title: 'Language Select' requirements: _access: 'TRUE' @@ -240,7 +241,7 @@ form_test.language_select: form_test.placeholder: path: '/form-test/placeholder-text' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testPlaceholder' + _form: '\Drupal\form_test\Form\FormTestPlaceholderTest' _title: 'Placeholder' requirements: _access: 'TRUE' @@ -248,7 +249,7 @@ form_test.placeholder: form_test.number: path: '/form-test/number' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testNumber' + _form: '\Drupal\form_test\Form\TestNumber' _title: 'Number' requirements: _access: 'TRUE' @@ -256,7 +257,7 @@ form_test.number: form_test.number_range: path: '/form-test/number/range' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testNumberRange' + _form: '\Drupal\form_test\Form\TestNumber' _title: 'Range' requirements: _access: 'TRUE' @@ -264,7 +265,7 @@ form_test.number_range: form_test.range: path: '/form-test/range' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testRange' + _form: '\Drupal\form_test\Form\TestRange' _title: 'Range' requirements: _access: 'TRUE' @@ -272,7 +273,7 @@ form_test.range: form_test.range_invalid: path: '/form-test/range/invalid' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testRangeInvalid' + _form: '\Drupal\form_test\Form\TestRangeInvalid' _title: 'Invalid range' requirements: _access: 'TRUE' @@ -280,7 +281,7 @@ form_test.range_invalid: form_test.color: path: '/form-test/color' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testColor' + _form: '\Drupal\form_test\Form\FormTestColor' _title: 'Color' requirements: _access: 'TRUE' @@ -288,7 +289,7 @@ form_test.color: form_test.checkboxes_radios: path: '/form-test/checkboxes-radios/{customize}' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testCheckboxesRadios' + _form: '\Drupal\form_test\Form\FormTestCheckboxesRadios' _title: 'Checkboxes, Radios' customize: FALSE requirements: @@ -297,7 +298,7 @@ form_test.checkboxes_radios: form_test.email: path: '/form-test/email' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testEmail' + _form: '\Drupal\form_test\Form\FormTestEmail' _title: 'E-Mail fields' requirements: _access: 'TRUE' @@ -305,7 +306,7 @@ form_test.email: form_test.url: path: '/form-test/url' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testUrl' + _form: '\Drupal\form_test\Form\TestUrl' _title: 'URL' requirements: _access: 'TRUE' @@ -329,7 +330,7 @@ form_test.input_forgery: form_test.rebuild_preservation: path: '/form-test/form-rebuild-preserve-values' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testRebuildPreservation' + _form: '\Drupal\form_test\Form\TestRebuildPreservation' _title: 'Form values preservation during rebuild test' requirements: _access: 'TRUE' @@ -337,7 +338,7 @@ form_test.rebuild_preservation: form_test.redirect: path: '/form-test/redirect' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testRedirect' + _form: '\Drupal\form_test\Form\TestRedirect' _title: 'Redirect test' requirements: _access: 'TRUE' @@ -353,7 +354,7 @@ form_test.label: form_test.state_persistence: path: '/form-test/state-persist' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testStatePersistence' + _form: '\Drupal\form_test\Form\TestStatePersistence' _title: 'Form state persistence without storage' requirements: _access: 'TRUE' @@ -361,7 +362,7 @@ form_test.state_persistence: form_test.clicked_button: path: '/form-test/clicked-button/{first}/{second}/{third}' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testClickedButton' + _form: '\Drupal\form_test\Form\FormTestClickedButton' _title: 'Clicked button test' first: NULL second: NULL @@ -372,7 +373,7 @@ form_test.clicked_button: form_test.checkboxes_zero: path: '/form-test/checkboxes-zero/{json}' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testCheckboxesZero' + _form: '\Drupal\form_test\Form\FormTestCheckboxesZero' _title: 'FAPI test involving checkboxes and zero' json: TRUE requirements: @@ -381,7 +382,7 @@ form_test.checkboxes_zero: form_test.required: path: '/form-test/required-attribute' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testRequired' + _form: '\Drupal\form_test\Form\TestRequired' _title: 'Required' requirements: _access: 'TRUE' @@ -389,7 +390,7 @@ form_test.required: form_test.button_class: path: '/form-test/button-class' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testButtonClass' + _form: '\Drupal\form_test\Form\FormTestButtonClass' _title: 'Button class testing' requirements: _access: 'TRUE' @@ -397,7 +398,7 @@ form_test.button_class: form_test.group_details: path: '/form-test/group-details' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testGroupDetails' + _form: '\Drupal\form_test\Form\FormTestGroupDetails' _title: 'Group details testing' requirements: _access: 'TRUE' @@ -405,7 +406,7 @@ form_test.group_details: form_test.group_container: path: '/form-test/group-container' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testGroupContainer' + _form: '\Drupal\form_test\Form\FormTestGroupContainer' _title: 'Group container testing' requirements: _access: 'TRUE' @@ -413,7 +414,7 @@ form_test.group_container: form_test.group_fieldset: path: '/form-test/group-fieldset' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testGroupFieldset' + _form: '\Drupal\form_test\Form\FormTestGroupFieldset' _title: 'Group fieldset testing' requirements: _access: 'TRUE' @@ -421,7 +422,7 @@ form_test.group_fieldset: form_test.group_vertical_tabs: path: '/form-test/group-vertical-tabs' defaults: - _content: '\Drupal\form_test\Form\FormTestForm::testGroupVerticalTabs' + _form: '\Drupal\form_test\Form\FormTestGroupVerticalTabs' _title: 'Group vertical tabs testing' requirements: _access: 'TRUE' diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php deleted file mode 100644 index ef8cc88..0000000 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormArrayPathTestForm.php +++ /dev/null @@ -1,43 +0,0 @@ - 'system.admin', - 'options' => array( - 'query' => array( - 'destination' => 'admin/config', - ), - ), - ); - } - - /** - * {@inheritdoc} - */ - public function getCancelText() { - return $this->t('ConfirmFormArrayPathTestForm::getCancelText().'); - } - -} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php deleted file mode 100644 index 43f8173..0000000 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/ConfirmFormTestForm.php +++ /dev/null @@ -1,78 +0,0 @@ -t('ConfirmFormTestForm::getQuestion().'); - } - - /** - * {@inheritdoc} - */ - public function getCancelRoute() { - return array( - 'route_name' => 'system.admin', - ); - } - - /** - * {@inheritdoc} - */ - public function getDescription() { - return $this->t('ConfirmFormTestForm::getDescription().'); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return $this->t('ConfirmFormTestForm::getConfirmText().'); - } - - /** - * {@inheritdoc} - */ - public function getCancelText() { - return $this->t('ConfirmFormTestForm::getCancelText().'); - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, array &$form_state) { - $form['element'] = array('#markup' => '

The ConfirmFormTestForm::buildForm() method was used for this form.

'); - - return parent::buildForm($form, $form_state); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - drupal_set_message($this->t('The ConfirmFormTestForm::submitForm() method was used for this form.')); - $form_state['redirect_route']['route_name'] = ''; - } - -} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormArrayPathTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormArrayPathTestForm.php new file mode 100644 index 0000000..563021e --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormArrayPathTestForm.php @@ -0,0 +1,43 @@ + 'system.admin', + 'options' => array( + 'query' => array( + 'destination' => 'admin/config', + ), + ), + ); + } + + /** + * {@inheritdoc} + */ + public function getCancelText() { + return $this->t('ConfirmFormArrayPathTestForm::getCancelText().'); + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormTestForm.php new file mode 100644 index 0000000..15d77f5 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/ConfirmFormTestForm.php @@ -0,0 +1,78 @@ +t('ConfirmFormTestForm::getQuestion().'); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + return array( + 'route_name' => 'system.admin', + ); + } + + /** + * {@inheritdoc} + */ + public function getDescription() { + return $this->t('ConfirmFormTestForm::getDescription().'); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return $this->t('ConfirmFormTestForm::getConfirmText().'); + } + + /** + * {@inheritdoc} + */ + public function getCancelText() { + return $this->t('ConfirmFormTestForm::getCancelText().'); + } + + /** + * {@inheritdoc} + */ + public function buildForm(array $form, array &$form_state) { + $form['element'] = array('#markup' => '

The ConfirmFormTestForm::buildForm() method was used for this form.

'); + + return parent::buildForm($form, $form_state); + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message($this->t('The ConfirmFormTestForm::submitForm() method was used for this form.')); + $form_state['redirect_route']['route_name'] = ''; + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormLabelTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormLabelTestForm.php new file mode 100644 index 0000000..f359d70 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormLabelTestForm.php @@ -0,0 +1,122 @@ + 'checkboxes', + '#title' => t('Checkboxes test'), + '#options' => array( + 'first-checkbox' => t('First checkbox'), + 'second-checkbox' => t('Second checkbox'), + 'third-checkbox' => t('Third checkbox'), + '0' => t('0'), + ), + ); + $form['form_radios_test'] = array( + '#type' => 'radios', + '#title' => t('Radios test'), + '#options' => array( + 'first-radio' => t('First radio'), + 'second-radio' => t('Second radio'), + 'third-radio' => t('Third radio'), + '0' => t('0'), + ), + // Test #field_prefix and #field_suffix placement. + '#field_prefix' => '' . t('Radios #field_prefix element') . '', + '#field_suffix' => '' . t('Radios #field_suffix element') . '', + ); + $form['form_checkbox_test'] = array( + '#type' => 'checkbox', + '#title' => t('Checkbox test'), + ); + $form['form_textfield_test_title_and_required'] = array( + '#type' => 'textfield', + '#title' => t('Textfield test for required with title'), + '#required' => TRUE, + ); + $form['form_textfield_test_no_title_required'] = array( + '#type' => 'textfield', + // We use an empty title, since not setting #title suppresses the label + // and required marker. + '#title' => '', + '#required' => TRUE, + ); + $form['form_textfield_test_title'] = array( + '#type' => 'textfield', + '#title' => t('Textfield test for title only'), + // Not required. + // Test #prefix and #suffix placement. + '#prefix' => '
' . t('Textfield #prefix element') . '
', + '#suffix' => '
' . t('Textfield #suffix element') . '
', + ); + $form['form_textfield_test_title_after'] = array( + '#type' => 'textfield', + '#title' => t('Textfield test for title after element'), + '#title_display' => 'after', + ); + $form['form_textfield_test_title_invisible'] = array( + '#type' => 'textfield', + '#title' => t('Textfield test for invisible title'), + '#title_display' => 'invisible', + ); + // Textfield test for title set not to display. + $form['form_textfield_test_title_no_show'] = array( + '#type' => 'textfield', + ); + // Checkboxes & radios with title as attribute. + $form['form_checkboxes_title_attribute'] = array( + '#type' => 'checkboxes', + '#title' => 'Checkboxes test', + '#title_display' => 'attribute', + '#options' => array( + 'first-checkbox' => 'First checkbox', + 'second-checkbox' => 'Second checkbox', + ), + '#required' => TRUE, + ); + $form['form_radios_title_attribute'] = array( + '#type' => 'radios', + '#title' => 'Radios test', + '#title_display' => 'attribute', + '#options' => array( + 'first-radio' => 'First radio', + 'second-radio' => 'Second radio', + ), + '#required' => TRUE, + ); + + 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/Form/FormTestAlterForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestAlterForm.php new file mode 100644 index 0000000..275eea5 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestAlterForm.php @@ -0,0 +1,43 @@ + 'textfield', + '#title' => 'Autocomplete 1', + '#autocomplete_route_name' => 'form_test.autocomplete_1', + ); + $form['autocomplete_2'] = array( + '#type' => 'textfield', + '#title' => 'Autocomplete 2', + '#autocomplete_route_name' => 'form_test.autocomplete_2', + '#autocomplete_route_parameters' => array('param' => 'value'), + ); + + 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/Form/FormTestButtonClass.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestButtonClass.php new file mode 100644 index 0000000..3aa43cb --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestButtonClass.php @@ -0,0 +1,50 @@ + 'button', + '#value' => 'test', + '#button_type' => 'foo', + ); + $form['delete'] = array( + '#type' => 'button', + '#value' => 'Delete', + '#button_type' => 'danger', + ); + + 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/Form/FormTestCheckboxesRadios.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestCheckboxesRadios.php new file mode 100644 index 0000000..0a69442 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestCheckboxesRadios.php @@ -0,0 +1,91 @@ + 'checkboxes', + '#title' => 'Checkboxes', + '#options' => array( + 0 => 'Zero', + 'foo' => 'Foo', + 1 => 'One', + 'bar' => 'Bar', + '>' => 'Special Char', + ), + ); + if ($customize) { + $form['checkboxes'] += array( + 'foo' => array( + '#description' => 'Enable to foo.', + ), + 1 => array( + '#weight' => 10, + ), + ); + } + + // Expand #type radios, setting custom element properties for some but not + // all options. + $form['radios'] = array( + '#type' => 'radios', + '#title' => 'Radios', + '#options' => array( + 0 => 'Zero', + 'foo' => 'Foo', + 1 => 'One', + 'bar' => 'Bar', + '>' => 'Special Char', + ), + ); + if ($customize) { + $form['radios'] += array( + 'foo' => array( + '#description' => 'Enable to foo.', + ), + 1 => array( + '#weight' => 10, + ), + ); + } + + $form['submit'] = array('#type' => 'submit', '#value' => '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/Form/FormTestCheckboxesZero.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestCheckboxesZero.php new file mode 100644 index 0000000..76e21b5 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestCheckboxesZero.php @@ -0,0 +1,69 @@ + t('Checkbox off'), + '#type' => 'checkboxes', + '#options' => array('foo', 'bar', 'baz'), + ); + $form['checkbox_zero_default'] = array( + '#title' => t('Zero default'), + '#type' => 'checkboxes', + '#options' => array('foo', 'bar', 'baz'), + '#default_value' => array(0), + ); + $form['checkbox_string_zero_default'] = array( + '#title' => t('Zero default (string)'), + '#type' => 'checkboxes', + '#options' => array('foo', 'bar', 'baz'), + '#default_value' => array('0'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Save', + ); + if ($json) { + $form['#submit'][] = '_form_test_submit_values_json'; + } + else { + $form['#submit'][] = 'Drupal\form_test\Form\FormTestCheckboxesZero::formTestCheckboxesZeroNoRedirect'; + } + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + + } + + public static function formTestCheckboxesZeroNoRedirect($form, &$form_state) { + $form_state['redirect'] = FALSE; + } +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestClickedButton.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestClickedButton.php new file mode 100644 index 0000000..e802209 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestClickedButton.php @@ -0,0 +1,103 @@ + 'Text', + '#type' => 'textfield', + ); + + // Loop through each path argument, addding buttons based on the information + // in the argument. For example, if the path is + // form-test/clicked-button/s/i/rb, then 3 buttons are added: a 'submit', an + // 'image_button', and a 'button' with #access=FALSE. This enables form.test + // to test a variety of combinations. + $i=0; + $args = array($first, $second, $third); + foreach ($args as $arg) { + $name = 'button' . ++$i; + // 's', 'b', or 'i' in the argument define the button type wanted. + if (strpos($arg, 's') !== FALSE) { + $type = 'submit'; + } + elseif (strpos($arg, 'b') !== FALSE) { + $type = 'button'; + } + elseif (strpos($arg, 'i') !== FALSE) { + $type = 'image_button'; + } + else { + $type = NULL; + } + if (isset($type)) { + $form[$name] = array( + '#type' => $type, + '#name' => $name, + ); + // Image buttons need a #src; the others need a #value. + if ($type == 'image_button') { + $form[$name]['#src'] = 'core/misc/druplicon.png'; + } + else { + $form[$name]['#value'] = $name; + } + // 'r' for restricted, so we can test that button click detection code + // correctly takes #access security into account. + if (strpos($arg, 'r') !== FALSE) { + $form[$name]['#access'] = FALSE; + } + } + } + + return $form; + } + + /** + *Form validation handler for the form_test_clicked_button() form. + */ + public function validateForm(array &$form, array &$form_state) { + if (isset($form_state['triggering_element'])) { + drupal_set_message(t('The clicked button is %name.', array('%name' => $form_state['triggering_element']['#name']))); + } + else { + drupal_set_message('There is no clicked button.'); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message('Submit handler for form_test_clicked_button executed.'); + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestColor.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestColor.php new file mode 100644 index 0000000..d963da1 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestColor.php @@ -0,0 +1,49 @@ + 'color', + '#title' => 'Color', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/FormTestEmail.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestEmail.php new file mode 100644 index 0000000..ed44316 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestEmail.php @@ -0,0 +1,57 @@ + 'email', + '#title' => 'E-Mail address', + '#description' => 'An e-mail address.', + ); + $form['email_required'] = array( + '#type' => 'email', + '#title' => 'Address', + '#required' => TRUE, + '#description' => 'A required e-mail address field.', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/FormTestEmptySelect.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestEmptySelect.php new file mode 100644 index 0000000..d854b87 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestEmptySelect.php @@ -0,0 +1,45 @@ + 'select', + '#title' => t('Empty Select'), + '#multiple' => FALSE, + '#options' => NULL, + ); + 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/Form/FormTestForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestForm.php index 6fa4ab0..7c7b47b 100644 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestForm.php +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestForm.php @@ -13,60 +13,6 @@ class FormTestForm { /** - * Wraps form_test_alter_form(). - * - * @todo Remove form_test_alter_form(). - */ - public function alterForm() { - return drupal_get_form('form_test_alter_form'); - } - - /** - * Wraps form_test_validate_form(). - * - * @todo Remove form_test_validate_form(). - */ - public function validateForm() { - return drupal_get_form('form_test_validate_form'); - } - - /** - * Wraps form_test_validate_required_form(). - * - * @todo Remove form_test_validate_required_form(). - */ - public function validateRequiredForm() { - return drupal_get_form('form_test_validate_required_form'); - } - - /** - * Wraps form_test_validate_required_form_no_title(). - * - * @todo Remove form_test_validate_required_form_no_title(). - */ - public function validateRequiredFormNoTitle() { - return drupal_get_form('form_test_validate_required_form_no_title'); - } - - /** - * Wraps form_test_limit_validation_errors_form(). - * - * @todo Remove form_test_limit_validation_errors_form(). - */ - public function validateFormWithErrorSuppression() { - return drupal_get_form('form_test_limit_validation_errors_form'); - } - - /** - * Wraps form_test_pattern_form(). - * - * @todo Remove form_test_pattern_form(). - */ - public function validatePattern() { - return drupal_get_form('form_test_pattern_form'); - } - - /** * Wraps _form_test_tableselect_multiple_true_form(). * * @todo Remove _form_test_tableselect_multiple_true_form(). @@ -121,15 +67,6 @@ public function testVerticalTabs() { } /** - * Wraps form_test_storage_form(). - * - * @todo Remove form_test_storage_form(). - */ - public function testStorage() { - return drupal_get_form('form_test_storage_form'); - } - - /** * Wraps form_test_wrapper_callback_form(). * * @todo Remove form_test_wrapper_callback_form(). @@ -139,24 +76,6 @@ public function testWrapperCallback() { } /** - * Wraps form_test_form_state_values_clean_form(). - * - * @todo Remove form_test_form_state_values_clean_form(). - */ - public function testFormStateClean() { - return drupal_get_form('form_test_form_state_values_clean_form'); - } - - /** - * Wraps form_test_form_state_values_clean_advanced_form(). - * - * @todo Remove form_test_form_state_values_clean_advanced_form(). - */ - public function testFormStateCleanAdvanced() { - return drupal_get_form('form_test_form_state_values_clean_advanced_form'); - } - - /** * Wraps _form_test_checkbox(). * * @todo Remove _form_test_checkbox(). @@ -184,96 +103,6 @@ public function testEmptySelect() { } /** - * Wraps form_test_language_select(). - * - * @todo Remove form_test_language_select(). - */ - public function testLanguageSelect() { - return drupal_get_form('form_test_language_select'); - } - - /** - * Wraps form_test_placeholder_test(). - * - * @todo Remove form_test_placeholder_test(). - */ - public function testPlaceholder() { - return drupal_get_form('form_test_placeholder_test'); - } - - /** - * Wraps form_test_number(). - * - * @todo Remove form_test_number(). - */ - public function testNumber() { - return drupal_get_form('form_test_number'); - } - - /** - * Wraps form_test_number(). - * - * @todo Remove form_test_number(). - */ - public function testNumberRange() { - return drupal_get_form('form_test_number', 'range'); - } - - /** - * Wraps form_test_range(). - * - * @todo Remove form_test_range(). - */ - public function testRange() { - return drupal_get_form('form_test_range'); - } - - /** - * Wraps form_test_range_invalid(). - * - * @todo Remove form_test_range_invalid(). - */ - public function testRangeInvalid() { - return drupal_get_form('form_test_range_invalid'); - } - - /** - * Wraps form_test_color(). - * - * @todo Remove form_test_color(). - */ - public function testColor() { - return drupal_get_form('form_test_color'); - } - - /** - * Wraps form_test_checkboxes_radios(). - * - * @todo Remove form_test_checkboxes_radios(). - */ - public function testCheckboxesRadios($customize) { - return drupal_get_form('form_test_checkboxes_radios', $customize); - } - - /** - * Wraps form_test_email(). - * - * @todo Remove form_test_email(). - */ - public function testEmail() { - return drupal_get_form('form_test_email'); - } - - /** - * Wraps form_test_url(). - * - * @todo Remove form_test_url(). - */ - public function testUrl() { - return drupal_get_form('form_test_url'); - } - - /** * Wraps _form_test_disabled_elements(). * * @todo Remove _form_test_disabled_elements(). @@ -292,24 +121,6 @@ public function testInputForgery() { } /** - * Wraps form_test_form_rebuild_preserve_values_form(). - * - * @todo Remove form_test_form_rebuild_preserve_values_form(). - */ - public function testRebuildPreservation() { - return drupal_get_form('form_test_form_rebuild_preserve_values_form'); - } - - /** - * Wraps form_test_redirect(). - * - * @todo Remove form_test_redirect(). - */ - public function testRedirect() { - return drupal_get_form('form_test_redirect'); - } - - /** * Wraps form_label_test_form(). * * @todo Remove form_label_test_form(). @@ -319,87 +130,6 @@ public function testLabel() { } /** - * Wraps form_test_state_persist(). - * - * @todo Remove form_test_state_persist(). - */ - public function testStatePersistence() { - return drupal_get_form('form_test_state_persist'); - } - - /** - * Wraps form_test_clicked_button(). - * - * @todo Remove form_test_clicked_button(). - */ - public function testClickedButton($first, $second, $third) { - return drupal_get_form('form_test_clicked_button', $first, $second, $third); - } - - /** - * Wraps form_test_checkboxes_zero(). - * - * @todo Remove form_test_checkboxes_zero(). - */ - public function testCheckboxesZero($json) { - return drupal_get_form('form_test_checkboxes_zero', $json); - } - - /** - * Wraps form_test_required_attribute(). - * - * @todo Remove form_test_required_attribute(). - */ - public function testRequired() { - return drupal_get_form('form_test_required_attribute'); - } - - /** - * Wraps form_test_button_class(). - * - * @todo Remove form_test_button_class(). - */ - public function testButtonClass() { - return drupal_get_form('form_test_button_class'); - } - - /** - * Wraps form_test_group_details(). - * - * @todo Remove form_test_group_details(). - */ - public function testGroupDetails() { - return drupal_get_form('form_test_group_details'); - } - - /** - * Wraps form_test_group_container(). - * - * @todo Remove form_test_group_container(). - */ - public function testGroupContainer() { - return drupal_get_form('form_test_group_container'); - } - - /** - * Wraps form_test_group_fieldset(). - * - * @todo Remove form_test_group_fieldset(). - */ - public function testGroupFieldset() { - return drupal_get_form('form_test_group_fieldset'); - } - - /** - * Wraps form_test_group_vertical_tabs(). - * - * @todo Remove form_test_group_vertical_tabs(). - */ - public function testGroupVerticalTabs() { - return drupal_get_form('form_test_group_vertical_tabs'); - } - - /** * Wraps form_test_form_state_database(). * * @todo Remove form_test_form_state_database(). diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupContainer.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupContainer.php new file mode 100644 index 0000000..4524da1 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupContainer.php @@ -0,0 +1,52 @@ + 'container', + ); + $form['meta'] = array( + '#type' => 'details', + '#title' => 'Group element', + '#group' => 'container', + ); + $form['meta']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in details element', + ); + + 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/Form/FormTestGroupDetails.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupDetails.php new file mode 100644 index 0000000..8d69613 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupDetails.php @@ -0,0 +1,52 @@ + 'details', + '#title' => 'Root element', + ); + $form['meta'] = array( + '#type' => 'details', + '#title' => 'Group element', + '#group' => 'details', + ); + $form['meta']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in details element', + ); + 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/Form/FormTestGroupFieldset.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupFieldset.php new file mode 100644 index 0000000..c2bda45 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupFieldset.php @@ -0,0 +1,52 @@ + 'fieldset', + '#title' => 'Fieldset', + ); + $form['meta'] = array( + '#type' => 'container', + '#title' => 'Group element', + '#group' => 'fieldset', + ); + $form['meta']['element'] = array( + '#type' => 'textfield', + '#title' => 'Nest in container element', + ); + 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/Form/FormTestGroupVerticalTabs.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupVerticalTabs.php new file mode 100644 index 0000000..8a8ced7 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestGroupVerticalTabs.php @@ -0,0 +1,60 @@ + 'vertical_tabs', + ); + $form['meta'] = array( + '#type' => 'details', + '#title' => 'First group element', + '#group' => 'vertical_tabs', + ); + $form['meta']['element'] = array( + '#type' => 'textfield', + '#title' => 'First nested element in details element', + ); + $form['meta_2'] = array( + '#type' => 'details', + '#title' => 'Second group element', + '#group' => 'vertical_tabs', + ); + $form['meta_2']['element_2'] = array( + '#type' => 'textfield', + '#title' => 'Second nested element in details element', + ); + 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/Form/FormTestLimitValidationErrorsForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestLimitValidationErrorsForm.php new file mode 100644 index 0000000..c64b4fd --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestLimitValidationErrorsForm.php @@ -0,0 +1,123 @@ + 'textfield', + '#title' => 'Title', + '#required' => TRUE, + ); + + $form['test'] = array( + '#title' => 'Test', + '#type' => 'textfield', + '#element_validate' => array( + 'Drupal\form_test\Form\FormTestLimitValidationErrorsForm::elementValidateTest' + ), + ); + $form['test_numeric_index'] = array( + '#tree' => TRUE, + ); + $form['test_numeric_index'][0] = array( + '#title' => 'Test (numeric index)', + '#type' => 'textfield', + '#element_validate' => array( + 'Drupal\form_test\Form\FormTestLimitValidationErrorsForm::elementValidateTest' + ), + ); + + $form['test_substring'] = array( + '#tree' => TRUE, + ); + $form['test_substring']['foo'] = array( + '#title' => 'Test (substring) foo', + '#type' => 'textfield', + '#element_validate' => array( + 'Drupal\form_test\Form\FormTestLimitValidationErrorsForm::elementValidateTest' + ), + ); + $form['test_substring']['foobar'] = array( + '#title' => 'Test (substring) foobar', + '#type' => 'textfield', + '#element_validate' => array( + 'Drupal\form_test\Form\FormTestLimitValidationErrorsForm::elementValidateTest' + ), + ); + + $form['actions']['partial'] = array( + '#type' => 'submit', + '#limit_validation_errors' => array(array('test')), + '#submit' => array('Drupal\form_test\Form\FormTestLimitValidationErrorsForm::formPartialSubmit'), + '#value' => t('Partial validate'), + ); + $form['actions']['partial_numeric_index'] = array( + '#type' => 'submit', + '#limit_validation_errors' => array(array('test_numeric_index', 0)), + '#submit' => array('Drupal\form_test\Form\FormTestLimitValidationErrorsForm::formPartialSubmit'), + '#value' => t('Partial validate (numeric index)'), + ); + $form['actions']['substring'] = array( + '#type' => 'submit', + '#limit_validation_errors' => array(array('test_substring', 'foo')), + '#submit' => array('Drupal\form_test\Form\FormTestLimitValidationErrorsForm::formPartialSubmit'), + '#value' => t('Partial validate (substring)'), + ); + $form['actions']['full'] = array( + '#type' => 'submit', + '#value' => t('Full validate'), + ); + return $form; + } + + /** + * Form element validation handler for the 'test' element. + */ + public static function elementValidateTest(&$element, &$form_state) { + if ($element['#value'] == 'invalid') { + form_error($element, $form_state, t('@label element is invalid', array('@label' => $element['#title']))); + } + } + + /** + * Form submit handler for the partial validation submit button. + */ + public static function formPartialSubmit($form, $form_state) { + // The title has not been validated, thus its value - in case of the test case + // an empty string - may not be set. + if (!isset($form_state['values']['title']) && isset($form_state['values']['test'])) { + drupal_set_message('Only validated values appear in the form values.'); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestPatternForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestPatternForm.php new file mode 100644 index 0000000..87fc5cb --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestPatternForm.php @@ -0,0 +1,67 @@ + 'textfield', + '#title' => 'One digit followed by lowercase letters', + '#pattern' => '[0-9][a-z]+', + ); + $form['tel'] = array( + '#type' => 'tel', + '#title' => 'Everything except numbers', + '#pattern' => '[^\d]*', + ); + $form['password'] = array( + '#type' => 'password', + '#title' => 'Password', + '#pattern' => '[01]+', + ); + $form['url'] = array( + '#type' => 'url', + '#title' => 'Client side validation', + '#decription' => 'Just client side validation, using the #pattern attribute.', + '#attributes' => array( + 'pattern' => '.*foo.*', + ), + '#pattern' => 'ignored', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/FormTestPlaceholderTest.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestPlaceholderTest.php new file mode 100644 index 0000000..feb0597 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestPlaceholderTest.php @@ -0,0 +1,46 @@ + $type, + '#title' => $type, + '#placeholder' => 'placeholder-text', + ); + } + 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/Form/FormTestValidateForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateForm.php new file mode 100644 index 0000000..b046b9a --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateForm.php @@ -0,0 +1,84 @@ + 'textfield', + '#title' => 'Name', + '#default_value' => '', + '#element_validate' => array(array($object, 'validateName')), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Save', + ); + + // To simplify this test, enable form caching and use form storage to + // remember our alteration. + $form_state['cache'] = TRUE; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function validateForm(array &$form, array &$form_state) { + if ($form_state['values']['name'] == 'validate') { + // Alter the form element. + $form['name']['#value'] = '#value changed by #validate'; + // Alter the submitted value in $form_state. + form_set_value($form['name'], 'value changed by form_set_value() in #validate', $form_state); + // Output the element's value from $form_state. + drupal_set_message(t('@label value: @value', array('@label' => $form['name']['#title'], '@value' => $form_state['values']['name']))); + + // Trigger a form validation error to see our changes. + form_set_error('', $form_state); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredForm.php new file mode 100644 index 0000000..3bfecfe --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredForm.php @@ -0,0 +1,90 @@ + 'textfield', + '#title' => 'Name', + '#required' => TRUE, + '#required_error' => t('Please enter a name.'), + ); + $form['checkboxes'] = array( + '#type' => 'checkboxes', + '#title' => 'Checkboxes', + '#options' => $options, + '#required' => TRUE, + '#form_test_required_error' => t('Please choose at least one option.'), + '#element_validate' => $validate, + ); + $form['select'] = array( + '#type' => 'select', + '#title' => 'Select', + '#options' => $options, + '#required' => TRUE, + '#form_test_required_error' => t('Please select something.'), + '#element_validate' => $validate, + ); + $form['radios'] = array( + '#type' => 'radios', + '#title' => 'Radios', + '#options' => $options, + '#required' => TRUE, + ); + $form['radios_optional'] = array( + '#type' => 'radios', + '#title' => 'Radios (optional)', + '#options' => $options, + ); + $form['radios_optional_default_value_false'] = array( + '#type' => 'radios', + '#title' => 'Radios (optional, with a default value of FALSE)', + '#options' => $options, + '#default_value' => FALSE, + ); + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit'); + return $form; + } + + public static function elementValidateTest(&$element, &$form_state) { + // Set a custom validation error on the #required element. + if (!empty($element['#required_but_empty']) && isset($element['#form_test_required_error'])) { + form_error($element, $form_state, $element['#form_test_required_error']); + } + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message('The form_test_validate_required_form form was submitted successfully.'); + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredFormNoTitle.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredFormNoTitle.php new file mode 100644 index 0000000..6ab9082 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/FormTestValidateRequiredFormNoTitle.php @@ -0,0 +1,45 @@ + 'textfield', + '#required' => TRUE, + ); + $form['actions'] = array('#type' => 'actions'); + $form['actions']['submit'] = array('#type' => 'submit', '#value' => 'Submit'); + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message('The form_test_validate_required_form_no_title form was submitted successfully.'); + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateClean.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateClean.php new file mode 100644 index 0000000..6875584 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateClean.php @@ -0,0 +1,52 @@ + TRUE); + $form['foo'] = array('#type' => 'submit', '#value' => t('Submit')); + $form['bar'] = array('#type' => 'submit', '#value' => t('Submit')); + $form['beer'] = array('#type' => 'value', '#value' => 1000); + $form['baz']['foo'] = array('#type' => 'button', '#value' => t('Submit')); + $form['baz']['baz'] = array('#type' => 'submit', '#value' => t('Submit')); + $form['baz']['beer'] = array('#type' => 'value', '#value' => 2000); + + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + form_state_values_clean($form_state); + // This won't have a proper JSON header, but Drupal doesn't check for that + // anyway so this is fine until it's replaced with a JsonResponse. + print drupal_json_encode($form_state['values']); + exit; + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateCleanAdvanced.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateCleanAdvanced.php new file mode 100644 index 0000000..b26105e --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestFormStateCleanAdvanced.php @@ -0,0 +1,51 @@ + 'managed_file', + '#title' => t('Image'), + '#upload_location' => 'public://', + '#default_value' => 0, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + return $form; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + form_state_values_clean($form_state); + print t('You WIN!'); + exit; + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestLanguageSelect.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestLanguageSelect.php new file mode 100644 index 0000000..e21e858 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestLanguageSelect.php @@ -0,0 +1,72 @@ + t('Languages: All'), + '#type' => 'language_select', + '#languages' => Language::STATE_ALL, + '#default_value' => 'xx', + ); + $form['languages_configurable'] = array( + '#title' => t('Languages: Configurable'), + '#type' => 'language_select', + '#languages' => Language::STATE_CONFIGURABLE, + '#default_value' => 'en', + ); + $form['languages_locked'] = array( + '#title' => t('Languages: Locked'), + '#type' => 'language_select', + '#languages' => Language::STATE_LOCKED, + ); + $form['languages_config_and_locked'] = array( + '#title' => t('Languages: Configurable and locked'), + '#type' => 'language_select', + '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, + '#default_value' => 'dummy_value', + ); + $form['language_custom_options'] = array( + '#title' => t('Languages: Custom'), + '#type' => 'language_select', + '#languages' => Language::STATE_CONFIGURABLE | Language::STATE_LOCKED, + '#options' => array('opt1' => 'First option', 'opt2' => 'Second option', 'opt3' => 'Third option'), + '#default_value' => 'opt2', + ); + + $form['submit'] = array('#type' => 'submit', '#value' => '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/Form/TestNumber.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestNumber.php new file mode 100644 index 0000000..f9e84c4 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestNumber.php @@ -0,0 +1,147 @@ + $element, + ); + + $form['integer_no_number'] = $base + array( + '#title' => 'Integer test, #no_error', + '#default_value' => '#no_number', + ); + $form['integer_no_step'] = $base + array( + '#title' => 'Integer test without step', + '#default_value' => 5, + ); + $form['integer_no_step_step_error'] = $base + array( + '#title' => 'Integer test without step, #step_error', + '#default_value' => 4.5, + ); + $form['integer_step'] = $base + array( + '#title' => 'Integer test with step', + '#default_value' => 5, + '#step' => 1, + ); + $form['integer_step_error'] = $base + array( + '#title' => 'Integer test, with step, #step_error', + '#default_value' => 5, + '#step' => 2, + ); + $form['integer_step_min'] = $base + array( + '#title' => 'Integer test with min value', + '#default_value' => 5, + '#min' => 0, + '#step' => 1, + ); + $form['integer_step_min_error'] = $base + array( + '#title' => 'Integer test with min value, #min_error', + '#default_value' => 5, + '#min' => 6, + '#step' => 1, + ); + $form['integer_step_max'] = $base + array( + '#title' => 'Integer test with max value', + '#default_value' => 5, + '#max' => 6, + '#step' => 1, + ); + $form['integer_step_max_error'] = $base + array( + '#title' => 'Integer test with max value, #max_error', + '#default_value' => 5, + '#max' => 4, + '#step' => 1, + ); + $form['integer_step_min_border'] = $base + array( + '#title' => 'Integer test with min border check', + '#default_value' => -1, + '#min' => -1, + '#step' => 1, + ); + $form['integer_step_max_border'] = $base + array( + '#title' => 'Integer test with max border check', + '#default_value' => 5, + '#max' => 5, + '#step' => 1, + ); + $form['integer_step_based_on_min'] = $base + array( + '#title' => 'Integer test with step based on min check', + '#default_value' => 3, + '#min' => -1, + '#step' => 2, + ); + $form['integer_step_based_on_min_error'] = $base + array( + '#title' => 'Integer test with step based on min check, #step_error', + '#default_value' => 4, + '#min' => -1, + '#step' => 2, + ); + $form['float_small_step'] = $base + array( + '#title' => 'Float test with a small step', + '#default_value' => 4, + '#step' => 0.0000000000001, + ); + $form['float_step_no_error'] = $base + array( + '#title' => 'Float test', + '#default_value' => 1.2, + '#step' => 0.3, + ); + $form['float_step_error'] = $base + array( + '#title' => 'Float test, #step_error', + '#default_value' => 1.3, + '#step' => 0.3, + ); + $form['float_step_hard_no_error'] = $base + array( + '#title' => 'Float test hard', + '#default_value' => 0.9411764729088, + '#step' => 0.00392156863712, + ); + $form['float_step_hard_error'] = $base + array( + '#title' => 'Float test hard, #step_error', + '#default_value' => 0.9411764, + '#step' => 0.00392156863, + ); + $form['float_step_any_no_error'] = $base + array( + '#title' => 'Arbitrary float', + '#default_value' => 0.839562930284, + '#step' => 'aNy', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/TestRange.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRange.php new file mode 100644 index 0000000..1a57ea4 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRange.php @@ -0,0 +1,77 @@ + 'range', + '#title' => 'Range with default value', + '#min' => 10, + '#max' => 20, + '#step' => 2, + '#default_value' => 18, + '#description' => 'The default value is 18.', + ); + $form['float'] = array( + '#type' => 'range', + '#title' => 'Float', + '#min' => 10, + '#max' => 11, + '#step' => 'any', + '#description' => 'Floating point number between 10 and 11.', + ); + $form['integer'] = array( + '#type' => 'range', + '#title' => 'Integer', + '#min' => 2, + '#max' => 8, + '#step' => 2, + '#description' => 'Even integer between 2 and 8.', + ); + $form['offset'] = array( + '#type' => 'range', + '#title' => 'Offset', + '#min' => 2.9, + '#max' => 10.9, + '#description' => 'Value between 2.9 and 10.9.', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/TestRangeInvalid.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRangeInvalid.php new file mode 100644 index 0000000..05ff095 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRangeInvalid.php @@ -0,0 +1,50 @@ + 'range', + '#min' => 10, + '#max' => 5, + '#title' => 'Invalid range', + '#description' => 'Minimum greater than maximum.', + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/Form/TestRebuildPreservation.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRebuildPreservation.php new file mode 100644 index 0000000..44ebcc7 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRebuildPreservation.php @@ -0,0 +1,103 @@ + array( + '#type' => 'checkbox', + '#title' => t('This checkbox defaults to unchecked.'), + '#default_value' => FALSE, + ), + 'checkbox_1_default_on' => array( + '#type' => 'checkbox', + '#title' => t('This checkbox defaults to checked.'), + '#default_value' => TRUE, + ), + 'text_1' => array( + '#type' => 'textfield', + '#title' => t('This textfield has a non-empty default value.'), + '#default_value' => 'DEFAULT 1', + ), + ); + // Provide an 'add more' button that rebuilds the form with an additional two + // checkboxes and a textfield. The test is to make sure that the rebuild + // triggered by this button preserves the user input values for the initial + // elements and initializes the new elements with the correct default values. + if (empty($form_state['storage']['add_more'])) { + $form['add_more'] = array( + '#type' => 'submit', + '#value' => 'Add more', + '#submit' => array('Drupal\form_test\Form\TestRebuildPreservation::addMore'), + ); + } + else { + $form += array( + 'checkbox_2_default_off' => array( + '#type' => 'checkbox', + '#title' => t('This checkbox defaults to unchecked.'), + '#default_value' => FALSE, + ), + 'checkbox_2_default_on' => array( + '#type' => 'checkbox', + '#title' => t('This checkbox defaults to checked.'), + '#default_value' => TRUE, + ), + 'text_2' => array( + '#type' => 'textfield', + '#title' => t('This textfield has a non-empty default value.'), + '#default_value' => 'DEFAULT 2', + ), + ); + } + // A submit button that finishes the form workflow (does not rebuild). + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Submit', + ); + return $form; + } + + /** + * Button submit handler for form_test_form_rebuild_preserve_values_form(). + */ + public static function addMore($form, &$form_state) { + // Rebuild, to test preservation of input values. + $form_state['storage']['add_more'] = TRUE; + $form_state['rebuild'] = TRUE; + } + + /** + * {@inheritdoc} + */ + public function submitForm(array &$form, array &$form_state) { + // Finish the workflow. Do not rebuild. + drupal_set_message(t('Form values: %values', array('%values' => var_export($form_state['values'], TRUE)))); + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRedirect.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRedirect.php new file mode 100644 index 0000000..c16ad8b --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRedirect.php @@ -0,0 +1,62 @@ + 'checkbox', + '#title' => t('Use redirection'), + ); + $form['destination'] = array( + '#type' => 'textfield', + '#title' => t('Redirect destination'), + '#states' => array( + 'visible' => array( + ':input[name="redirection"]' => array('checked' => TRUE), + ), + ), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; + } + + /** + * {@inheritdoc} + * Form submit handler to test different redirect behaviours. + */ + public function submitForm(array &$form, array &$form_state) { + if (!empty($form_state['values']['redirection'])) { + $form_state['redirect'] = !empty($form_state['values']['destination']) ? $form_state['values']['destination'] : NULL; + } + else { + $form_state['redirect'] = FALSE; + } + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRequired.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRequired.php new file mode 100644 index 0000000..3c5e222 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestRequired.php @@ -0,0 +1,47 @@ + $type, + '#required' => TRUE, + '#title' => $type, + ); + } + + return $form; + } + + /** + * {@inheritdoc} + * Form submit handler to test different redirect behaviours. + */ + public function submitForm(array &$form, array &$form_state) { + + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestSelect.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestSelect.php new file mode 100644 index 0000000..2c2ebbf --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestSelect.php @@ -0,0 +1,135 @@ + 'select', + '#options' => drupal_map_assoc(array('one', 'two', 'three')), + ); + + $form['select'] = $base + array( + '#title' => '#default_value one', + '#default_value' => 'one', + ); + $form['select_required'] = $base + array( + '#title' => '#default_value one, #required', + '#required' => TRUE, + '#default_value' => 'one', + ); + $form['select_optional'] = $base + array( + '#title' => '#default_value one, not #required', + '#required' => FALSE, + '#default_value' => 'one', + ); + $form['empty_value'] = $base + array( + '#title' => '#default_value one, #required, #empty_value 0', + '#required' => TRUE, + '#default_value' => 'one', + '#empty_value' => 0, + ); + $form['empty_value_one'] = $base + array( + '#title' => '#default_value = #empty_value, #required', + '#required' => TRUE, + '#default_value' => 'one', + '#empty_value' => 'one', + ); + + $form['no_default'] = $base + array( + '#title' => 'No #default_value, #required', + '#required' => TRUE, + ); + $form['no_default_optional'] = $base + array( + '#title' => 'No #default_value, not #required', + '#required' => FALSE, + '#description' => 'Should result in "one" because it is not required and there is no #empty_value requested, so default browser behavior of preselecting first option is in effect.', + ); + $form['no_default_optional_empty_value'] = $base + array( + '#title' => 'No #default_value, not #required, #empty_value empty string', + '#empty_value' => '', + '#required' => FALSE, + '#description' => 'Should result in an empty string (due to #empty_value) because it is optional.', + ); + + $form['no_default_empty_option'] = $base + array( + '#title' => 'No #default_value, #required, #empty_option', + '#required' => TRUE, + '#empty_option' => '- Choose -', + ); + $form['no_default_empty_option_optional'] = $base + array( + '#title' => 'No #default_value, not #required, #empty_option', + '#empty_option' => '- Dismiss -', + '#description' => 'Should result in an empty string (default of #empty_value) because it is optional.', + ); + + $form['no_default_empty_value'] = $base + array( + '#title' => 'No #default_value, #required, #empty_value 0', + '#required' => TRUE, + '#empty_value' => 0, + '#description' => 'Should never result in 0.', + ); + $form['no_default_empty_value_one'] = $base + array( + '#title' => 'No #default_value, #required, #empty_value one', + '#required' => TRUE, + '#empty_value' => 'one', + '#description' => 'A mistakenly assigned #empty_value contained in #options should not be valid.', + ); + $form['no_default_empty_value_optional'] = $base + array( + '#title' => 'No #default_value, not #required, #empty_value 0', + '#required' => FALSE, + '#empty_value' => 0, + '#description' => 'Should result in 0 because it is optional.', + ); + + $form['multiple'] = $base + array( + '#title' => '#multiple, #default_value two', + '#default_value' => array('two'), + '#multiple' => TRUE, + ); + $form['multiple_no_default'] = $base + array( + '#title' => '#multiple, no #default_value', + '#multiple' => TRUE, + ); + $form['multiple_no_default_required'] = $base + array( + '#title' => '#multiple, #required, no #default_value', + '#required' => TRUE, + '#multiple' => TRUE, + ); + + $form['submit'] = array('#type' => 'submit', '#value' => '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/Form/TestStatePersistence.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestStatePersistence.php new file mode 100644 index 0000000..62888bb --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestStatePersistence.php @@ -0,0 +1,53 @@ + 'textfield', + '#title' => 'title', + '#default_value' => 'DEFAULT', + '#required' => TRUE, + ); + $form_state['value'] = 'State persisted.'; + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Submit'), + ); + + return $form; + } + + /** + * {@inheritdoc} + * Form submit handler to test different redirect behaviours. + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message($form_state['value']); + $form_state['rebuild'] = TRUE; + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestStorage.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestStorage.php new file mode 100644 index 0000000..48e5e82 --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestStorage.php @@ -0,0 +1,126 @@ + array( + 'title' => 'none', + 'value' => '', + ), + ); + } + // Count how often the form is constructed. + $_SESSION['constructions']++; + drupal_set_message("Form constructions: " . $_SESSION['constructions']); + + $form['title'] = array( + '#type' => 'textfield', + '#title' => 'Title', + '#default_value' => $form_state['storage']['thing']['title'], + '#required' => TRUE, + ); + $form['value'] = array( + '#type' => 'textfield', + '#title' => 'Value', + '#default_value' => $form_state['storage']['thing']['value'], + '#element_validate' => array('\Drupal\form_test\Form\TestStorage::elementValidateValueCached'), + ); + $form['continue_button'] = array( + '#type' => 'button', + '#value' => 'Reset', + // Rebuilds the form without keeping the values. + ); + $form['continue_submit'] = array( + '#type' => 'submit', + '#value' => 'Continue submit', + '#submit' => array('\Drupal\form_test\Form\TestStorage::formContinueSubmit'), + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => 'Save', + ); + + if (isset($_REQUEST['cache'])) { + // Manually activate caching, so we can test that the storage keeps working + // when it's enabled. + $form_state['cache'] = TRUE; + } + + return $form; + } + + /** + * Form element validation handler for 'value' element in form_test_storage_form(). + * + * Tests updating of cached form storage during validation. + */ + public static function elementValidateValueCached($element, &$form_state) { + // If caching is enabled and we receive a certain value, change the storage. + // This presumes that another submitted form value triggers a validation error + // elsewhere in the form. Form API should still update the cached form storage + // though. + if (isset($_REQUEST['cache']) && $form_state['values']['value'] == 'change_title') { + $form_state['storage']['thing']['changed'] = TRUE; + } + } + + /** + * Form submit handler to continue multi-step form. + */ + public static function formContinueSubmit($form, &$form_state) { + $form_state['storage']['thing']['title'] = $form_state['values']['title']; + $form_state['storage']['thing']['value'] = $form_state['values']['value']; + $form_state['rebuild'] = TRUE; + } + + /** + * {@inheritdoc} + * Form submit handler to test different redirect behaviours. + */ + public function submitForm(array &$form, array &$form_state) { + drupal_set_message("Title: " . check_plain($form_state['values']['title'])); + drupal_set_message("Form constructions: " . $_SESSION['constructions']); + if (isset($form_state['storage']['thing']['changed'])) { + drupal_set_message("The thing has been changed."); + } + $form_state['redirect_route']['route_name'] = ''; + } + +} diff --git a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestUrl.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestUrl.php new file mode 100644 index 0000000..8f8c02f --- /dev/null +++ b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/Form/TestUrl.php @@ -0,0 +1,54 @@ + 'url', + '#title' => 'Optional URL', + '#description' => 'An optional URL field.', + ); + $form['url_required'] = array( + '#type' => 'url', + '#title' => 'Required URL', + '#description' => 'A required URL field.', + '#required' => TRUE, + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => '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/FormTestAutocompleteForm.php b/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestAutocompleteForm.php deleted file mode 100644 index 6cedc3a..0000000 --- a/core/modules/system/tests/modules/form_test/lib/Drupal/form_test/FormTestAutocompleteForm.php +++ /dev/null @@ -1,49 +0,0 @@ - 'textfield', - '#title' => 'Autocomplete 1', - '#autocomplete_route_name' => 'form_test.autocomplete_1', - ); - $form['autocomplete_2'] = array( - '#type' => 'textfield', - '#title' => 'Autocomplete 2', - '#autocomplete_route_name' => 'form_test.autocomplete_2', - '#autocomplete_route_parameters' => array('param' => 'value'), - ); - - return $form; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, array &$form_state) { - } - -}