You are here

public function PathElementFormTest::buildForm in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Element/PathElementFormTest.php \Drupal\system\Tests\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/modules/system/src/Tests/Element/PathElementFormTest.php, line 74
Contains \Drupal\system\Tests\Element\PathElementFormTest.

Class

PathElementFormTest
Tests PathElement validation and conversion functionality.

Namespace

Drupal\system\Tests\Element

Code

public function buildForm(array $form, FormStateInterface $form_state) {

  // A required validated path.
  $form['required_validate'] = array(
    '#type' => 'path',
    '#required' => TRUE,
    '#title' => 'required_validate',
    '#convert_path' => PathElement::CONVERT_NONE,
  );

  // A non validated required path.
  $form['required_non_validate'] = array(
    '#type' => 'path',
    '#required' => TRUE,
    '#title' => 'required_non_validate',
    '#convert_path' => PathElement::CONVERT_NONE,
    '#validate_path' => FALSE,
  );

  // A non required validated path.
  $form['optional_validate'] = array(
    '#type' => 'path',
    '#required' => FALSE,
    '#title' => 'optional_validate',
    '#convert_path' => PathElement::CONVERT_NONE,
  );

  // A non required converted path.
  $form['optional_validate'] = array(
    '#type' => 'path',
    '#required' => FALSE,
    '#title' => 'optional_validate',
    '#convert_path' => PathElement::CONVERT_ROUTE,
  );

  // A converted required validated path.
  $form['required_validate_route'] = array(
    '#type' => 'path',
    '#required' => TRUE,
    '#title' => 'required_validate_route',
  );

  // A converted required validated path.
  $form['required_validate_url'] = array(
    '#type' => 'path',
    '#required' => TRUE,
    '#title' => 'required_validate_url',
    '#convert_path' => PathElement::CONVERT_URL,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}