You are here

public function AjaxFormsTestLazyLoadForm::buildForm in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestLazyLoadForm::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/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php, line 28
Contains \Drupal\ajax_forms_test\Form\AjaxFormsTestLazyLoadForm.

Class

AjaxFormsTestLazyLoadForm
Form builder: Builds a form that triggers a simple AJAX callback.

Namespace

Drupal\ajax_forms_test\Form

Code

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

  // We attach a JavaScript setting, so that one of the generated AJAX
  // commands will be a settings command. We can then check the settings
  // command to ensure that the 'currentPath' setting is not part
  // of the Ajax response.
  $form['#attached']['drupalSettings']['test'] = 'currentPathUpdate';
  $form['add_files'] = array(
    '#title' => $this
      ->t('Add files'),
    '#type' => 'checkbox',
    '#default_value' => FALSE,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => $this
      ->t('Submit'),
    '#ajax' => array(
      'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper',
      'callback' => 'ajax_forms_test_lazy_load_form_ajax',
    ),
    '#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>',
  );
  return $form;
}