You are here

public function FormTestMachineNameForm::buildForm in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/form_test/src/Form/FormTestMachineNameForm.php \Drupal\form_test\Form\FormTestMachineNameForm::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/tests/modules/form_test/src/Form/FormTestMachineNameForm.php, line 26

Class

FormTestMachineNameForm
Form constructor for testing #type 'machine_name' elements.

Namespace

Drupal\form_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['machine_name_1_label'] = [
    '#type' => 'textfield',
    '#title' => 'Machine name 1 label',
  ];
  $form['machine_name_1'] = [
    '#type' => 'machine_name',
    '#title' => 'Machine name 1',
    '#description' => 'A machine name.',
    '#machine_name' => [
      'source' => [
        'machine_name_1_label',
      ],
    ],
  ];
  $form['machine_name_2_label'] = [
    '#type' => 'textfield',
    '#title' => 'Machine name 2 label',
  ];
  $form['machine_name_2'] = [
    '#type' => 'machine_name',
    '#title' => 'Machine name 2',
    '#description' => 'Another machine name.',
    '#machine_name' => [
      'source' => [
        'machine_name_2_label',
      ],
    ],
  ];
  $form['machine_name_3_label'] = [
    '#type' => 'textfield',
    '#title' => 'Machine name 3 label',
    '#default_value' => 'Yet another machine name',
  ];
  $form['machine_name_3'] = [
    '#type' => 'machine_name',
    '#title' => 'Machine name 3',
    '#description' => 'Another machine name.',
    '#machine_name' => [
      'source' => [
        'machine_name_3_label',
      ],
    ],
  ];
  $form['submit'] = [
    '#type' => 'submit',
    '#value' => 'Submit',
  ];
  return $form;
}