You are here

public function PathElementFormTest::buildForm in Drupal 8

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

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

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

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'] = [
    '#type' => 'path',
    '#required' => FALSE,
    '#title' => 'optional_validate',
    '#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;
}