function AjaxFormsTestImageButtonForm::buildForm

Same name and namespace in other branches
  1. 9 core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestImageButtonForm::buildForm()
  2. 8.9.x core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestImageButtonForm::buildForm()
  3. 10 core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php \Drupal\ajax_forms_test\Form\AjaxFormsTestImageButtonForm::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/AjaxFormsTestImageButtonForm.php, line 28

Class

AjaxFormsTestImageButtonForm
Form builder: Builds a form that has image button with an ajax callback.

Namespace

Drupal\ajax_forms_test\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form['image_button'] = [
    '#type' => 'image_button',
    '#name' => 'image_button',
    '#src' => 'core/misc/icons/787878/cog.svg',
    '#attributes' => [
      'alt' => $this->t('Edit'),
    ],
    '#op' => 'edit',
    '#ajax' => [
      'callback' => [
        Callbacks::class,
        'imageButtonCallback',
      ],
    ],
    '#suffix' => '<div id="ajax_image_button_result">Image button not pressed yet.</div>',
  ];
  return $form;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.