AjaxFormsTestImageButtonForm.php in Drupal 10
File
core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php
View source
<?php
namespace Drupal\ajax_forms_test\Form;
use Drupal\ajax_forms_test\Callbacks;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
class AjaxFormsTestImageButtonForm extends FormBase {
public function getFormId() {
return 'ajax_forms_test_image_button_form';
}
public function buildForm(array $form, FormStateInterface $form_state) {
$object = new Callbacks();
$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' => [
$object,
'imageButtonCallback',
],
],
'#suffix' => '<div id="ajax_image_button_result">Image button not pressed yet.</div>',
];
return $form;
}
public function submitForm(array &$form, FormStateInterface $form_state) {
}
}