function PathElementFormTest::buildForm

Same name and namespace in other branches
  1. 9 core/tests/Drupal/KernelTests/Core/Element/PathElementFormTest.php \Drupal\KernelTests\Core\Element\PathElementFormTest::buildForm()
  2. 8.9.x core/tests/Drupal/KernelTests/Core/Element/PathElementFormTest.php \Drupal\KernelTests\Core\Element\PathElementFormTest::buildForm()
  3. 10 core/tests/Drupal/KernelTests/Core/Element/PathElementFormTest.php \Drupal\KernelTests\Core\Element\PathElementFormTest::buildForm()

Overrides FormInterface::buildForm

File

core/tests/Drupal/KernelTests/Core/Element/PathElementFormTest.php, line 68

Class

PathElementFormTest
Tests PathElement validation and conversion functionality.

Namespace

Drupal\KernelTests\Core\Element

Code

public function buildForm(array $form, FormStateInterface $form_state) {
    // A required validated path.
    $form['required_validate'] = [
        '#type' => 'path',
        '#required' => TRUE,
        '#title' => 'required_validate',
        '#convert_path' => PathElement::CONVERT_NONE,
    ];
    // A non validated required path.
    $form['required_non_validate'] = [
        '#type' => 'path',
        '#required' => TRUE,
        '#title' => 'required_non_validate',
        '#convert_path' => PathElement::CONVERT_NONE,
        '#validate_path' => FALSE,
    ];
    // A non required validated path.
    $form['optional_validate'] = [
        '#type' => 'path',
        '#required' => FALSE,
        '#title' => 'optional_validate',
        '#convert_path' => PathElement::CONVERT_NONE,
    ];
    // A non required converted path.
    $form['optional_validate_route'] = [
        '#type' => 'path',
        '#required' => FALSE,
        '#title' => 'optional_validate_route',
        '#convert_path' => PathElement::CONVERT_ROUTE,
    ];
    // A converted required validated path.
    $form['required_validate_route'] = [
        '#type' => 'path',
        '#required' => TRUE,
        '#title' => 'required_validate_route',
    ];
    // A converted required validated path.
    $form['required_validate_url'] = [
        '#type' => 'path',
        '#required' => TRUE,
        '#title' => 'required_validate_url',
        '#convert_path' => PathElement::CONVERT_URL,
    ];
    $form['submit'] = [
        '#type' => 'submit',
        '#value' => t('Submit'),
    ];
    return $form;
}

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