20754ffd991d26d6f6389b05f586f6f7f8dc257c
[yaffs-website] / web / core / modules / system / tests / modules / ajax_forms_test / src / Form / AjaxFormsTestImageButtonForm.php
1 <?php
2
3 namespace Drupal\ajax_forms_test\Form;
4
5 use Drupal\ajax_forms_test\Callbacks;
6 use Drupal\Core\Form\FormBase;
7 use Drupal\Core\Form\FormStateInterface;
8
9 /**
10  * Form builder: Builds a form that has image button with an ajax callback.
11  */
12 class AjaxFormsTestImageButtonForm extends FormBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public function getFormId() {
18     return 'ajax_forms_test_image_button_form';
19   }
20
21   /**
22    * {@inheritdoc}
23    */
24   public function buildForm(array $form, FormStateInterface $form_state) {
25     $object = new Callbacks();
26     $form['image_button'] = [
27       '#type' => 'image_button',
28       '#name' => 'image_button',
29       '#src' => 'core/misc/icons/787878/cog.svg',
30       '#attributes' => ['alt' => $this->t('Edit')],
31       '#op' => 'edit',
32       '#ajax' => [
33         'callback' => [$object, 'imageButtonCallback'],
34       ],
35       '#suffix' => '<div id="ajax_image_button_result">Image button not pressed yet.</div>',
36     ];
37
38     return $form;
39   }
40
41   /**
42    * {@inheritdoc}
43    */
44   public function submitForm(array &$form, FormStateInterface $form_state) {
45     // No submit code needed.
46   }
47
48 }