function ElementsTableSelectTest::formSubmitHelper

Same name in other branches
  1. 9 core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php \Drupal\Tests\system\Functional\Form\ElementsTableSelectTest::formSubmitHelper()
  2. 8.9.x core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php \Drupal\Tests\system\Functional\Form\ElementsTableSelectTest::formSubmitHelper()
  3. 11.x core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php \Drupal\Tests\system\Functional\Form\ElementsTableSelectTest::formSubmitHelper()

Helper function for the option check test to submit a form while collecting errors.

@internal param $form_element A form element to test. A form element to test.

Parameters

array $form: Nested array of form elements that comprise the form.

array $edit: An array containing post data.

Return value

array An array containing the processed form, the form_state and any errors.

2 calls to ElementsTableSelectTest::formSubmitHelper()
ElementsTableSelectTest::testMultipleFalseOptionChecker in core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php
Tests error handling for invalid tableselect values with radio buttons.
ElementsTableSelectTest::testMultipleTrueOptionChecker in core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php
Tests error handling for invalid tableselect values with checkboxes.

File

core/modules/system/tests/src/Functional/Form/ElementsTableSelectTest.php, line 213

Class

ElementsTableSelectTest
Tests the tableselect form element for expected behavior.

Namespace

Drupal\Tests\system\Functional\Form

Code

private function formSubmitHelper($form, $edit) {
    $form_id = $this->randomMachineName();
    $form_state = new FormState();
    $form['op'] = [
        '#type' => 'submit',
        '#value' => 'Submit',
    ];
    // The form token CSRF protection should not interfere with this test, so we
    // bypass it by setting the token to FALSE.
    $form['#token'] = FALSE;
    $edit['form_id'] = $form_id;
    // Disable page redirect for forms submitted programmatically. This is a
    // solution to skip the redirect step (there are no pages, then the redirect
    // isn't possible).
    $form_state->disableRedirect();
    $form_state->setUserInput($edit);
    $form_state->setFormObject(new StubForm($form_id, $form));
    \Drupal::formBuilder()->prepareForm($form_id, $form, $form_state);
    \Drupal::formBuilder()->processForm($form_id, $form, $form_state);
    $errors = $form_state->getErrors();
    // Clear errors and messages.
    \Drupal::messenger()->deleteAll();
    $form_state->clearErrors();
    // Return the processed form together with form_state and errors
    // to allow the caller low-level access to the form.
    return [
        $form,
        $form_state,
        $errors,
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.