diff --git a/core/.phpstan-baseline.php b/core/.phpstan-baseline.php index 71c573d603a9de452b246f70e09982a578b458e2..e1b70ca644a919a69fae3612c7e263ad3f2adc56 100644 --- a/core/.phpstan-baseline.php +++ b/core/.phpstan-baseline.php @@ -34909,6 +34909,180 @@ 'count' => 1, 'path' => __DIR__ . '/modules/system/tests/modules/advisory_feed_test/src/AdvisoryTestClientMiddleware.php', ]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_add_css_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_after_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_alert_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_announce_assertive_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_announce_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_announce_polite_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_append_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_before_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_changed_asterisk_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_changed_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_css_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_data_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_double_announce_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_html_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_insert_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_invoke_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_prepend_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_remove_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_restripe_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_advanced_commands_settings_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_lazy_load_form_ajax\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_validation_form_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Function ajax_forms_test_validation_number_form_callback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:checkboxCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:checkboxGroupCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:dateCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:datetimeCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:imageButtonCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; +$ignoreErrors[] = [ + 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Callbacks\\:\\:selectCallback\\(\\) has no return type specified\\.$#', + 'identifier' => 'missingType.return', + 'count' => 1, + 'path' => __DIR__ . '/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php', +]; $ignoreErrors[] = [ 'message' => '#^Method Drupal\\\\ajax_forms_test\\\\Form\\\\AjaxFormsTestAjaxElementsForm\\:\\:submitForm\\(\\) has no return type specified\\.$#', 'identifier' => 'missingType.return', diff --git a/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module new file mode 100644 index 0000000000000000000000000000000000000000..f73c9904846b2021469ba0f62a246188efd0dddb --- /dev/null +++ b/core/modules/system/tests/modules/ajax_forms_test/ajax_forms_test.module @@ -0,0 +1,253 @@ +<?php + +/** + * @file + * Mock module for Ajax forms testing. + */ + +declare(strict_types=1); + +use Drupal\Core\Ajax\AddCssCommand; +use Drupal\Core\Ajax\AfterCommand; +use Drupal\Core\Ajax\AjaxResponse; +use Drupal\Core\Ajax\AlertCommand; +use Drupal\Core\Ajax\AnnounceCommand; +use Drupal\Core\Ajax\AppendCommand; +use Drupal\Core\Ajax\BeforeCommand; +use Drupal\Core\Ajax\ChangedCommand; +use Drupal\Core\Ajax\CssCommand; +use Drupal\Core\Ajax\DataCommand; +use Drupal\Core\Ajax\HtmlCommand; +use Drupal\Core\Ajax\InsertCommand; +use Drupal\Core\Ajax\InvokeCommand; +use Drupal\Core\Ajax\PrependCommand; +use Drupal\Core\Ajax\RemoveCommand; +use Drupal\Core\Ajax\RestripeCommand; +use Drupal\Core\Ajax\SettingsCommand; +use Drupal\Core\Form\FormStateInterface; + +/** + * Ajax form callback: Selects 'after'. + */ +function ajax_forms_test_advanced_commands_after_callback($form, FormStateInterface $form_state) { + $selector = '#after_div'; + + $response = new AjaxResponse(); + $response->addCommand(new AfterCommand($selector, "This will be placed after")); + return $response; +} + +/** + * Ajax form callback: Selects 'alert'. + */ +function ajax_forms_test_advanced_commands_alert_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new AlertCommand('Alert')); + return $response; +} + +/** + * Ajax form callback: Selects 'announce' with no priority specified. + */ +function ajax_forms_test_advanced_commands_announce_callback($form, FormStateInterface $form_state) { + return (new AjaxResponse())->addCommand(new AnnounceCommand('Default announcement.')); +} + +/** + * Ajax form callback: Selects 'announce' with 'polite' priority. + */ +function ajax_forms_test_advanced_commands_announce_polite_callback($form, FormStateInterface $form_state) { + return (new AjaxResponse())->addCommand(new AnnounceCommand('Polite announcement.', 'polite')); +} + +/** + * Ajax form callback: Selects 'announce' with 'assertive' priority. + */ +function ajax_forms_test_advanced_commands_announce_assertive_callback($form, FormStateInterface $form_state) { + return (new AjaxResponse())->addCommand(new AnnounceCommand('Assertive announcement.', 'assertive')); +} + +/** + * Ajax form callback: Selects 'announce' with two announce commands returned. + */ +function ajax_forms_test_advanced_commands_double_announce_callback($form, FormStateInterface $form_state) { + return (new AjaxResponse())->addCommand(new AnnounceCommand('Assertive announcement.', 'assertive')) + ->addCommand(new AnnounceCommand('Another announcement.')); +} + +/** + * Ajax form callback: Selects 'append'. + */ +function ajax_forms_test_advanced_commands_append_callback($form, FormStateInterface $form_state) { + $selector = '#append_div'; + $response = new AjaxResponse(); + $response->addCommand(new AppendCommand($selector, "Appended text")); + return $response; +} + +/** + * Ajax form callback: Selects 'before'. + */ +function ajax_forms_test_advanced_commands_before_callback($form, FormStateInterface $form_state) { + $selector = '#before_div'; + $response = new AjaxResponse(); + $response->addCommand(new BeforeCommand($selector, "Before text")); + return $response; +} + +/** + * Ajax form callback: Selects 'changed'. + */ +function ajax_forms_test_advanced_commands_changed_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new ChangedCommand('#changed_div')); + return $response; +} + +/** + * Ajax form callback: Selects 'changed' with asterisk marking inner div. + */ +function ajax_forms_test_advanced_commands_changed_asterisk_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new ChangedCommand('#changed_div', '#changed_div_mark_this')); + return $response; +} + +/** + * Ajax form callback: Selects 'css'. + */ +function ajax_forms_test_advanced_commands_css_callback($form, FormStateInterface $form_state) { + $selector = '#css_div'; + $color = 'blue'; + + $response = new AjaxResponse(); + $response->addCommand(new CssCommand($selector, ['background-color' => $color])); + return $response; +} + +/** + * Ajax form callback: Selects 'data'. + */ +function ajax_forms_test_advanced_commands_data_callback($form, FormStateInterface $form_state) { + $selector = '#data_div'; + $response = new AjaxResponse(); + $response->addCommand(new DataCommand($selector, 'test_key', 'test_value')); + return $response; +} + +/** + * Ajax form callback: Selects 'invoke'. + */ +function ajax_forms_test_advanced_commands_invoke_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new InvokeCommand('#invoke_div', 'addClass', ['error'])); + return $response; +} + +/** + * Ajax form callback: Selects 'html'. + */ +function ajax_forms_test_advanced_commands_html_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new HtmlCommand('#html_div', 'replacement text')); + return $response; +} + +/** + * Ajax form callback: Selects 'insert'. + */ +function ajax_forms_test_advanced_commands_insert_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new InsertCommand('#insert_div', 'insert replacement text')); + return $response; +} + +/** + * Ajax form callback: Selects 'prepend'. + */ +function ajax_forms_test_advanced_commands_prepend_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new PrependCommand('#prepend_div', "prepended text")); + return $response; +} + +/** + * Ajax form callback: Selects 'remove'. + */ +function ajax_forms_test_advanced_commands_remove_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new RemoveCommand('#remove_text')); + return $response; +} + +/** + * Ajax form callback: Selects 'restripe'. + */ +function ajax_forms_test_advanced_commands_restripe_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new RestripeCommand('#restripe_table')); + return $response; +} + +/** + * Ajax form callback: Selects 'settings'. + */ +function ajax_forms_test_advanced_commands_settings_callback($form, FormStateInterface $form_state) { + $setting['ajax_forms_test']['foo'] = 42; + $response = new AjaxResponse(); + $response->addCommand(new SettingsCommand($setting)); + return $response; +} + +/** + * Ajax callback for 'add_css'. + */ +function ajax_forms_test_advanced_commands_add_css_callback($form, FormStateInterface $form_state) { + $response = new AjaxResponse(); + $response->addCommand(new AddCssCommand([ + [ + 'href' => 'my/file.css', + 'media' => 'all', + ], + [ + 'href' => 'https://example.com/css?family=Open+Sans', + 'media' => 'all', + ], + ])); + return $response; +} + +/** + * Ajax form callback: Selects the 'driver_text' element of the validation form. + */ +function ajax_forms_test_validation_form_callback($form, FormStateInterface $form_state) { + \Drupal::messenger()->addStatus("ajax_forms_test_validation_form_callback invoked"); + \Drupal::messenger()->addStatus(t("Callback: driver_text=%driver_text, spare_required_field=%spare_required_field", ['%driver_text' => $form_state->getValue('driver_text'), '%spare_required_field' => $form_state->getValue('spare_required_field')])); + return ['#markup' => '<div id="message_area">ajax_forms_test_validation_form_callback at ' . date('c') . '</div>']; +} + +/** + * Ajax form callback: Selects the 'driver_number' element of the validation form. + */ +function ajax_forms_test_validation_number_form_callback($form, FormStateInterface $form_state) { + \Drupal::messenger()->addStatus("ajax_forms_test_validation_number_form_callback invoked"); + \Drupal::messenger()->addStatus(t("Callback: driver_number=%driver_number, spare_required_field=%spare_required_field", ['%driver_number' => $form_state->getValue('driver_number'), '%spare_required_field' => $form_state->getValue('spare_required_field')])); + return ['#markup' => '<div id="message_area_number">ajax_forms_test_validation_number_form_callback at ' . date('c') . '</div>']; +} + +/** + * AJAX form callback: Selects for the ajax_forms_test_lazy_load_form() form. + */ +function ajax_forms_test_lazy_load_form_ajax($form, FormStateInterface $form_state) { + $build = [ + '#markup' => 'new content', + ]; + + if ($form_state->getValue('add_files')) { + $build['#attached']['library'][] = 'system/admin'; + $build['#attached']['library'][] = 'system/drupal.system'; + $build['#attached']['drupalSettings']['ajax_forms_test_lazy_load_form_submit'] = 'executed'; + } + + return $build; +} diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php index df777954adffc3794da11f1c82bdd60d89ab836b..dfbed10b4164640c4e73a381430cebf2a21b5871 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Callbacks.php @@ -4,23 +4,9 @@ namespace Drupal\ajax_forms_test; -use Drupal\Core\Ajax\AddCssCommand; -use Drupal\Core\Ajax\AfterCommand; use Drupal\Core\Ajax\AjaxResponse; -use Drupal\Core\Ajax\AlertCommand; -use Drupal\Core\Ajax\AnnounceCommand; -use Drupal\Core\Ajax\AppendCommand; -use Drupal\Core\Ajax\BeforeCommand; -use Drupal\Core\Ajax\ChangedCommand; -use Drupal\Core\Ajax\CssCommand; use Drupal\Core\Ajax\DataCommand; use Drupal\Core\Ajax\HtmlCommand; -use Drupal\Core\Ajax\InsertCommand; -use Drupal\Core\Ajax\InvokeCommand; -use Drupal\Core\Ajax\PrependCommand; -use Drupal\Core\Ajax\RemoveCommand; -use Drupal\Core\Ajax\RestripeCommand; -use Drupal\Core\Ajax\SettingsCommand; use Drupal\Core\Form\FormStateInterface; /** @@ -31,7 +17,7 @@ class Callbacks { /** * Ajax callback triggered by select. */ - public static function selectCallback($form, FormStateInterface $form_state): AjaxResponse { + public function selectCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); $response->addCommand(new HtmlCommand('#ajax_selected_color', $form_state->getValue('select'))); $response->addCommand(new DataCommand('#ajax_selected_color', 'form_state_value_select', $form_state->getValue('select'))); @@ -41,7 +27,7 @@ public static function selectCallback($form, FormStateInterface $form_state): Aj /** * Ajax callback triggered by date. */ - public static function dateCallback($form, FormStateInterface $form_state): AjaxResponse { + public function dateCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); $date = $form_state->getValue('date'); $response->addCommand(new HtmlCommand('#ajax_date_value', sprintf('<div>%s</div>', $date))); @@ -52,7 +38,7 @@ public static function dateCallback($form, FormStateInterface $form_state): Ajax /** * Ajax callback triggered by datetime. */ - public static function datetimeCallback($form, FormStateInterface $form_state): AjaxResponse { + public function datetimeCallback($form, FormStateInterface $form_state) { $datetime = $form_state->getValue('datetime')['date'] . ' ' . $form_state->getValue('datetime')['time']; $response = new AjaxResponse(); @@ -64,7 +50,7 @@ public static function datetimeCallback($form, FormStateInterface $form_state): /** * Ajax callback triggered by checkbox. */ - public static function checkboxCallback($form, FormStateInterface $form_state): AjaxResponse { + public function checkboxCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); $response->addCommand(new HtmlCommand('#ajax_checkbox_value', $form_state->getValue('checkbox') ? 'checked' : 'unchecked')); $response->addCommand(new DataCommand('#ajax_checkbox_value', 'form_state_value_select', (int) $form_state->getValue('checkbox'))); @@ -74,7 +60,7 @@ public static function checkboxCallback($form, FormStateInterface $form_state): /** * Ajax callback to confirm image button was submitted. */ - public static function imageButtonCallback($form, FormStateInterface $form_state): AjaxResponse { + public function imageButtonCallback($form, FormStateInterface $form_state) { $response = new AjaxResponse(); $response->addCommand(new HtmlCommand('#ajax_image_button_result', "<div id='ajax-1-more-div'>Something witty!</div>")); return $response; @@ -83,234 +69,8 @@ public static function imageButtonCallback($form, FormStateInterface $form_state /** * Ajax callback triggered by the checkbox in a #group. */ - public static function checkboxGroupCallback($form, FormStateInterface $form_state): array { + public function checkboxGroupCallback($form, FormStateInterface $form_state) { return $form['checkbox_in_group_wrapper']; } - /** - * Ajax form callback: Selects 'after'. - */ - public static function advancedCommandsAfterCallback($form, FormStateInterface $form_state): AjaxResponse { - $selector = '#after_div'; - - $response = new AjaxResponse(); - $response->addCommand(new AfterCommand($selector, "This will be placed after")); - return $response; - } - - /** - * Ajax form callback: Selects 'alert'. - */ - public static function advancedCommandsAlertCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new AlertCommand('Alert')); - return $response; - } - - /** - * Ajax form callback: Selects 'announce' with no priority specified. - */ - public static function advancedCommandsAnnounceCallback($form, FormStateInterface $form_state): AjaxResponse { - return (new AjaxResponse())->addCommand(new AnnounceCommand('Default announcement.')); - } - - /** - * Ajax form callback: Selects 'announce' with 'polite' priority. - */ - public static function advancedCommandsAnnouncePoliteCallback($form, FormStateInterface $form_state): AjaxResponse { - return (new AjaxResponse())->addCommand(new AnnounceCommand('Polite announcement.', 'polite')); - } - - /** - * Ajax form callback: Selects 'announce' with 'assertive' priority. - */ - public static function advancedCommandsAnnounceAssertiveCallback($form, FormStateInterface $form_state): AjaxResponse { - return (new AjaxResponse())->addCommand(new AnnounceCommand('Assertive announcement.', 'assertive')); - } - - /** - * Ajax form callback: Selects 'announce' with two announce commands returned. - */ - public static function advancedCommandsDoubleAnnounceCallback($form, FormStateInterface $form_state): AjaxResponse { - return (new AjaxResponse())->addCommand(new AnnounceCommand('Assertive announcement.', 'assertive')) - ->addCommand(new AnnounceCommand('Another announcement.')); - } - - /** - * Ajax form callback: Selects 'append'. - */ - public static function advancedCommandsAppendCallback($form, FormStateInterface $form_state): AjaxResponse { - $selector = '#append_div'; - $response = new AjaxResponse(); - $response->addCommand(new AppendCommand($selector, "Appended text")); - return $response; - } - - /** - * Ajax form callback: Selects 'before'. - */ - public static function advancedCommandsBeforeCallback($form, FormStateInterface $form_state): AjaxResponse { - $selector = '#before_div'; - $response = new AjaxResponse(); - $response->addCommand(new BeforeCommand($selector, "Before text")); - return $response; - } - - /** - * Ajax form callback: Selects 'changed'. - */ - public static function advancedCommandsChangedCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new ChangedCommand('#changed_div')); - return $response; - } - - /** - * Ajax form callback: Selects 'changed' with asterisk marking inner div. - */ - public static function advancedCommandsChangedAsteriskCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new ChangedCommand('#changed_div', '#changed_div_mark_this')); - return $response; - } - - /** - * Ajax form callback: Selects 'css'. - */ - public static function advancedCommandsCssCallback($form, FormStateInterface $form_state): AjaxResponse { - $selector = '#css_div'; - $color = 'blue'; - - $response = new AjaxResponse(); - $response->addCommand(new CssCommand($selector, ['background-color' => $color])); - return $response; - } - - /** - * Ajax form callback: Selects 'data'. - */ - public static function advancedCommandsDataCallback($form, FormStateInterface $form_state): AjaxResponse { - $selector = '#data_div'; - $response = new AjaxResponse(); - $response->addCommand(new DataCommand($selector, 'test_key', 'test_value')); - return $response; - } - - /** - * Ajax form callback: Selects 'invoke'. - */ - public static function advancedCommandsInvokeCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new InvokeCommand('#invoke_div', 'addClass', ['error'])); - return $response; - } - - /** - * Ajax form callback: Selects 'html'. - */ - public static function advancedCommandsHtmlCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new HtmlCommand('#html_div', 'replacement text')); - return $response; - } - - /** - * Ajax form callback: Selects 'insert'. - */ - public static function advancedCommandsInsertCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new InsertCommand('#insert_div', 'insert replacement text')); - return $response; - } - - /** - * Ajax form callback: Selects 'prepend'. - */ - public static function advancedCommandsPrependCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new PrependCommand('#prepend_div', "prepended text")); - return $response; - } - - /** - * Ajax form callback: Selects 'remove'. - */ - public static function advancedCommandsRemoveCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new RemoveCommand('#remove_text')); - return $response; - } - - /** - * Ajax form callback: Selects 'restripe'. - */ - public static function advancedCommandsRestripeCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new RestripeCommand('#restripe_table')); - return $response; - } - - /** - * Ajax form callback: Selects 'settings'. - */ - public static function advancedCommandsSettingsCallback($form, FormStateInterface $form_state): AjaxResponse { - $setting['ajax_forms_test']['foo'] = 42; - $response = new AjaxResponse(); - $response->addCommand(new SettingsCommand($setting)); - return $response; - } - - /** - * Ajax callback for 'add_css'. - */ - public static function advancedCommandsAddCssCallback($form, FormStateInterface $form_state): AjaxResponse { - $response = new AjaxResponse(); - $response->addCommand(new AddCssCommand([ - [ - 'href' => 'my/file.css', - 'media' => 'all', - ], - [ - 'href' => 'https://example.com/css?family=Open+Sans', - 'media' => 'all', - ], - ])); - return $response; - } - - /** - * Ajax form callback: Selects the 'driver_text' element of the validation form. - */ - public static function validationFormCallback($form, FormStateInterface $form_state): array { - \Drupal::messenger()->addStatus("ajax_forms_test_validation_form_callback invoked"); - \Drupal::messenger()->addStatus(t("Callback: driver_text=%driver_text, spare_required_field=%spare_required_field", ['%driver_text' => $form_state->getValue('driver_text'), '%spare_required_field' => $form_state->getValue('spare_required_field')])); - return ['#markup' => '<div id="message_area">ajax_forms_test_validation_form_callback at ' . date('c') . '</div>']; - } - - /** - * Ajax form callback: Selects the 'driver_number' element of the validation form. - */ - public static function validationNumberFormCallback($form, FormStateInterface $form_state): array { - \Drupal::messenger()->addStatus("ajax_forms_test_validation_number_form_callback invoked"); - \Drupal::messenger()->addStatus(t("Callback: driver_number=%driver_number, spare_required_field=%spare_required_field", ['%driver_number' => $form_state->getValue('driver_number'), '%spare_required_field' => $form_state->getValue('spare_required_field')])); - return ['#markup' => '<div id="message_area_number">ajax_forms_test_validation_number_form_callback at ' . date('c') . '</div>']; - } - - /** - * AJAX form callback: Selects for the ajax_forms_test_lazy_load_form() form. - */ - public static function lazyLoadFormAjax($form, FormStateInterface $form_state): array { - $build = [ - '#markup' => 'new content', - ]; - - if ($form_state->getValue('add_files')) { - $build['#attached']['library'][] = 'system/admin'; - $build['#attached']['library'][] = 'system/drupal.system'; - $build['#attached']['drupalSettings']['ajax_forms_test_lazy_load_form_submit'] = 'executed'; - } - - return $build; - } - } diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php index f7c0c9e49bae1fb1f14d6c0c10d45f880a37bfde..41da97106d00ce2f5abd756225cf07dfa556bfe3 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestAjaxElementsForm.php @@ -26,10 +26,12 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + $callback_object = new Callbacks(); + $form['date'] = [ '#type' => 'date', '#ajax' => [ - 'callback' => [Callbacks::class, 'dateCallback'], + 'callback' => [$callback_object, 'dateCallback'], ], '#suffix' => '<div id="ajax_date_value">No date yet selected</div>', ]; @@ -37,7 +39,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { $form['datetime'] = [ '#type' => 'datetime', '#ajax' => [ - 'callback' => [Callbacks::class, 'datetimeCallback'], + 'callback' => [$callback_object, 'datetimeCallback'], 'wrapper' => 'ajax_datetime_value', ], ]; diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php index 8b59f9f411768a711bd3bce47c8b1a98f5d70c13..1ee090d4a05cbddb02dcf6a9a34c870c6a0b8f1f 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestCommandsForm.php @@ -4,7 +4,6 @@ namespace Drupal\ajax_forms_test\Form; -use Drupal\ajax_forms_test\Callbacks; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -33,7 +32,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'After': Click to put something after the div"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAfterCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_after_callback', ], '#suffix' => '<div id="after_div">Something can be inserted after this</div>', ]; @@ -43,7 +42,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Alert': Click to alert"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAlertCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_alert_callback', ], ]; @@ -52,7 +51,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Announce': Click to announce"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAnnounceCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_announce_callback', ], ]; @@ -61,7 +60,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Announce': Click to announce with 'polite' priority"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAnnouncePoliteCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_announce_polite_callback', ], ]; @@ -70,7 +69,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Announce': Click to announce with 'assertive' priority"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAnnounceAssertiveCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_announce_assertive_callback', ], ]; @@ -79,7 +78,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Announce': Click to announce twice"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsDoubleAnnounceCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_double_announce_callback', ], ]; @@ -88,7 +87,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'Append': Click to append something"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAppendCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_append_callback', ], '#suffix' => '<div id="append_div">Append inside this div</div>', ]; @@ -98,7 +97,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'before': Click to put something before the div"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsBeforeCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_before_callback', ], '#suffix' => '<div id="before_div">Insert something before this.</div>', ]; @@ -108,7 +107,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX changed: Click to mark div changed."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsChangedCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_changed_callback', ], '#suffix' => '<div id="changed_div"> <div id="changed_div_mark_this">This div can be marked as changed or not.</div></div>', ]; @@ -117,7 +116,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX changed: Click to mark div changed with asterisk."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsChangedAsteriskCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_changed_asterisk_callback', ], ]; @@ -126,7 +125,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("Set the '#box' div to be blue."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsCssCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_css_callback', ], '#suffix' => '<div id="css_div" style="height: 50px; width: 50px; border: 1px solid black"> box</div>', ]; @@ -137,7 +136,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX data command: Issue command."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsDataCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_data_callback', ], '#suffix' => '<div id="data_div">Data attached to this div.</div>', ]; @@ -147,7 +146,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX invoke command: Invoke addClass() method."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsHtmlCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_invoke_callback', ], '#suffix' => '<div id="invoke_div">Original contents</div>', ]; @@ -157,7 +156,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX html: Replace the HTML in a selector."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsHtmlCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_html_callback', ], '#suffix' => '<div id="html_div">Original contents</div>', ]; @@ -167,7 +166,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX insert: Let client insert based on #ajax['method']."), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsInsertCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_insert_callback', 'method' => 'prepend', ], '#suffix' => '<div id="insert_div">Original contents</div>', @@ -178,7 +177,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'prepend': Click to prepend something"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsPrependCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_prepend_callback', ], '#suffix' => '<div id="prepend_div">Something will be prepended to this div. </div>', ]; @@ -188,7 +187,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t("AJAX 'remove': Click to remove text"), '#type' => 'submit', '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsRemoveCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_remove_callback', ], '#suffix' => '<div id="remove_div"><div id="remove_text">text to be removed</div></div>', ]; @@ -198,7 +197,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t("AJAX 'restripe' command"), '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsRestripeCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_restripe_callback', ], '#suffix' => '<div id="restripe_div"> <table id="restripe_table" style="border: 1px solid black" > @@ -214,7 +213,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t("AJAX 'settings' command"), '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsSettingsCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_settings_callback', ], ]; @@ -223,7 +222,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'submit', '#value' => $this->t("AJAX 'add_css' command"), '#ajax' => [ - 'callback' => [Callbacks::class, 'advancedCommandsAddCssCallback'], + 'callback' => 'ajax_forms_test_advanced_commands_add_css_callback', ], ]; diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php index 40804d11cc713c3e8eec86a0d2ae1b01686d6165..a3970f711d6e633c8b726288d1fbc9cdb67446d1 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestImageButtonForm.php @@ -26,6 +26,7 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + $object = new Callbacks(); $form['image_button'] = [ '#type' => 'image_button', '#name' => 'image_button', @@ -33,7 +34,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#attributes' => ['alt' => $this->t('Edit')], '#op' => 'edit', '#ajax' => [ - 'callback' => [Callbacks::class, 'imageButtonCallback'], + 'callback' => [$object, 'imageButtonCallback'], ], '#suffix' => '<div id="ajax_image_button_result">Image button not pressed yet.</div>', ]; diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php index 49ffba1656e03c0732c30395b491297625068481..eb657a3f751f322b3d4bf12cb053fa99ecdb8897 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestLazyLoadForm.php @@ -4,7 +4,6 @@ namespace Drupal\ajax_forms_test\Form; -use Drupal\ajax_forms_test\Callbacks; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -41,7 +40,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#value' => $this->t('Submit'), '#ajax' => [ 'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper', - 'callback' => [Callbacks::class, 'lazyLoadFormAjax'], + 'callback' => 'ajax_forms_test_lazy_load_form_ajax', ], '#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>', ]; diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php index 1cd1478d8062dc700774f51467e749496912ec22..346afaabc5776449b3262538ceda54bbc062869a 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestSimpleForm.php @@ -26,6 +26,8 @@ public function getFormId() { * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { + $object = new Callbacks(); + $form = []; $form['select'] = [ '#title' => $this->t('Color'), @@ -36,7 +38,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { 'blue' => 'blue', ], '#ajax' => [ - 'callback' => [Callbacks::class, 'selectCallback'], + 'callback' => [$object, 'selectCallback'], ], '#suffix' => '<div id="ajax_selected_color">No color yet selected</div>', ]; @@ -45,7 +47,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('Test checkbox'), '#ajax' => [ - 'callback' => [Callbacks::class, 'checkboxCallback'], + 'callback' => [$object, 'checkboxCallback'], ], '#suffix' => '<div id="ajax_checkbox_value">No action yet</div>', ]; @@ -85,7 +87,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'checkbox', '#title' => $this->t('AJAX checkbox in a group'), '#ajax' => [ - 'callback' => [Callbacks::class, 'checkboxGroupCallback'], + 'callback' => [$object, 'checkboxGroupCallback'], 'wrapper' => 'checkbox-wrapper', ], ], @@ -99,7 +101,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#group' => 'nested_group', '#title' => $this->t('AJAX checkbox in a nested group'), '#ajax' => [ - 'callback' => [Callbacks::class, 'checkboxGroupCallback'], + 'callback' => [$object, 'checkboxGroupCallback'], 'wrapper' => 'checkbox-wrapper', ], ], diff --git a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php index 405f18206b3fd8aca9c937789fd512bf0eac5441..f9a67ecd4f06750809c2599e6e3016d2c1144976 100644 --- a/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php +++ b/core/modules/system/tests/modules/ajax_forms_test/src/Form/AjaxFormsTestValidationForm.php @@ -4,7 +4,6 @@ namespace Drupal\ajax_forms_test\Form; -use Drupal\ajax_forms_test\Callbacks; use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; @@ -32,7 +31,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'textfield', '#default_value' => $form_state->getValue('driver_text', ''), '#ajax' => [ - 'callback' => [Callbacks::class, 'validationFormCallback'], + 'callback' => 'ajax_forms_test_validation_form_callback', 'wrapper' => 'message_area', 'method' => 'replaceWith', ], @@ -45,7 +44,7 @@ public function buildForm(array $form, FormStateInterface $form_state) { '#type' => 'number', '#default_value' => $form_state->getValue('driver_number', ''), '#ajax' => [ - 'callback' => [Callbacks::class, 'validationNumberFormCallback'], + 'callback' => 'ajax_forms_test_validation_number_form_callback', 'wrapper' => 'message_area_number', 'method' => 'replaceWith', ],