function TriggeringElementProgrammedTest::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/ Form/ TriggeringElementProgrammedTest.php, line 29  
Class
- TriggeringElementProgrammedTest
 - Tests detection of triggering_element for programmed form submissions.
 
Namespace
Drupal\KernelTests\Core\FormCode
public function buildForm(array $form, FormStateInterface $form_state) {
  $form['one'] = [
    '#type' => 'textfield',
    '#title' => 'One',
    '#required' => TRUE,
  ];
  $form['two'] = [
    '#type' => 'textfield',
    '#title' => 'Two',
    '#required' => TRUE,
  ];
  $form['actions'] = [
    '#type' => 'actions',
  ];
  $user_input = $form_state->getUserInput();
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => 'Save',
    '#limit_validation_errors' => [
      [
        $user_input['section'],
      ],
    ],
    // Required for #limit_validation_errors.
'#submit' => [
      [
        $this,
        'submitForm',
      ],
    ],
  ];
  return $form;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.