Skip to content
Snippets Groups Projects
Commit 38de8a6c authored by catch's avatar catch
Browse files

Issue #3495959 by nikolay shapovalov, nicxvan, smustgrave, catch, larowlan:...

Issue #3495959 by nikolay shapovalov, nicxvan, smustgrave, catch, larowlan: Move helpers in ajax_forms_test.module and delete it
parent 6e30fe2f
No related branches found
No related tags found
1 merge request!617Issue #3043725: Provide a Entity Handler for user cancelation
Pipeline #404553 passed with warnings
Showing
with 279 additions and 468 deletions
......@@ -34909,180 +34909,6 @@
'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',
<?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;
}
......@@ -4,9 +4,23 @@
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;
/**
......@@ -17,7 +31,7 @@ class Callbacks {
/**
* Ajax callback triggered by select.
*/
public function selectCallback($form, FormStateInterface $form_state) {
public static function selectCallback($form, FormStateInterface $form_state): AjaxResponse {
$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')));
......@@ -27,7 +41,7 @@ public function selectCallback($form, FormStateInterface $form_state) {
/**
* Ajax callback triggered by date.
*/
public function dateCallback($form, FormStateInterface $form_state) {
public static function dateCallback($form, FormStateInterface $form_state): AjaxResponse {
$response = new AjaxResponse();
$date = $form_state->getValue('date');
$response->addCommand(new HtmlCommand('#ajax_date_value', sprintf('<div>%s</div>', $date)));
......@@ -38,7 +52,7 @@ public function dateCallback($form, FormStateInterface $form_state) {
/**
* Ajax callback triggered by datetime.
*/
public function datetimeCallback($form, FormStateInterface $form_state) {
public static function datetimeCallback($form, FormStateInterface $form_state): AjaxResponse {
$datetime = $form_state->getValue('datetime')['date'] . ' ' . $form_state->getValue('datetime')['time'];
$response = new AjaxResponse();
......@@ -50,7 +64,7 @@ public function datetimeCallback($form, FormStateInterface $form_state) {
/**
* Ajax callback triggered by checkbox.
*/
public function checkboxCallback($form, FormStateInterface $form_state) {
public static function checkboxCallback($form, FormStateInterface $form_state): AjaxResponse {
$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')));
......@@ -60,7 +74,7 @@ public function checkboxCallback($form, FormStateInterface $form_state) {
/**
* Ajax callback to confirm image button was submitted.
*/
public function imageButtonCallback($form, FormStateInterface $form_state) {
public static function imageButtonCallback($form, FormStateInterface $form_state): AjaxResponse {
$response = new AjaxResponse();
$response->addCommand(new HtmlCommand('#ajax_image_button_result', "<div id='ajax-1-more-div'>Something witty!</div>"));
return $response;
......@@ -69,8 +83,234 @@ public function imageButtonCallback($form, FormStateInterface $form_state) {
/**
* Ajax callback triggered by the checkbox in a #group.
*/
public function checkboxGroupCallback($form, FormStateInterface $form_state) {
public static function checkboxGroupCallback($form, FormStateInterface $form_state): array {
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;
}
}
......@@ -26,12 +26,10 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$callback_object = new Callbacks();
$form['date'] = [
'#type' => 'date',
'#ajax' => [
'callback' => [$callback_object, 'dateCallback'],
'callback' => [Callbacks::class, 'dateCallback'],
],
'#suffix' => '<div id="ajax_date_value">No date yet selected</div>',
];
......@@ -39,7 +37,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
$form['datetime'] = [
'#type' => 'datetime',
'#ajax' => [
'callback' => [$callback_object, 'datetimeCallback'],
'callback' => [Callbacks::class, 'datetimeCallback'],
'wrapper' => 'ajax_datetime_value',
],
];
......
......@@ -4,6 +4,7 @@
namespace Drupal\ajax_forms_test\Form;
use Drupal\ajax_forms_test\Callbacks;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -32,7 +33,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' => 'ajax_forms_test_advanced_commands_after_callback',
'callback' => [Callbacks::class, 'advancedCommandsAfterCallback'],
],
'#suffix' => '<div id="after_div">Something can be inserted after this</div>',
];
......@@ -42,7 +43,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Alert': Click to alert"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_alert_callback',
'callback' => [Callbacks::class, 'advancedCommandsAlertCallback'],
],
];
......@@ -51,7 +52,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Announce': Click to announce"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_announce_callback',
'callback' => [Callbacks::class, 'advancedCommandsAnnounceCallback'],
],
];
......@@ -60,7 +61,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Announce': Click to announce with 'polite' priority"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_announce_polite_callback',
'callback' => [Callbacks::class, 'advancedCommandsAnnouncePoliteCallback'],
],
];
......@@ -69,7 +70,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Announce': Click to announce with 'assertive' priority"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_announce_assertive_callback',
'callback' => [Callbacks::class, 'advancedCommandsAnnounceAssertiveCallback'],
],
];
......@@ -78,7 +79,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Announce': Click to announce twice"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_double_announce_callback',
'callback' => [Callbacks::class, 'advancedCommandsDoubleAnnounceCallback'],
],
];
......@@ -87,7 +88,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'Append': Click to append something"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_append_callback',
'callback' => [Callbacks::class, 'advancedCommandsAppendCallback'],
],
'#suffix' => '<div id="append_div">Append inside this div</div>',
];
......@@ -97,7 +98,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' => 'ajax_forms_test_advanced_commands_before_callback',
'callback' => [Callbacks::class, 'advancedCommandsBeforeCallback'],
],
'#suffix' => '<div id="before_div">Insert something before this.</div>',
];
......@@ -107,7 +108,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX changed: Click to mark div changed."),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_changed_callback',
'callback' => [Callbacks::class, 'advancedCommandsChangedCallback'],
],
'#suffix' => '<div id="changed_div"> <div id="changed_div_mark_this">This div can be marked as changed or not.</div></div>',
];
......@@ -116,7 +117,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' => 'ajax_forms_test_advanced_commands_changed_asterisk_callback',
'callback' => [Callbacks::class, 'advancedCommandsChangedAsteriskCallback'],
],
];
......@@ -125,7 +126,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("Set the '#box' div to be blue."),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_css_callback',
'callback' => [Callbacks::class, 'advancedCommandsCssCallback'],
],
'#suffix' => '<div id="css_div" style="height: 50px; width: 50px; border: 1px solid black"> box</div>',
];
......@@ -136,7 +137,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX data command: Issue command."),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_data_callback',
'callback' => [Callbacks::class, 'advancedCommandsDataCallback'],
],
'#suffix' => '<div id="data_div">Data attached to this div.</div>',
];
......@@ -146,7 +147,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX invoke command: Invoke addClass() method."),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_invoke_callback',
'callback' => [Callbacks::class, 'advancedCommandsHtmlCallback'],
],
'#suffix' => '<div id="invoke_div">Original contents</div>',
];
......@@ -156,7 +157,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX html: Replace the HTML in a selector."),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_html_callback',
'callback' => [Callbacks::class, 'advancedCommandsHtmlCallback'],
],
'#suffix' => '<div id="html_div">Original contents</div>',
];
......@@ -166,7 +167,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' => 'ajax_forms_test_advanced_commands_insert_callback',
'callback' => [Callbacks::class, 'advancedCommandsInsertCallback'],
'method' => 'prepend',
],
'#suffix' => '<div id="insert_div">Original contents</div>',
......@@ -177,7 +178,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'prepend': Click to prepend something"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_prepend_callback',
'callback' => [Callbacks::class, 'advancedCommandsPrependCallback'],
],
'#suffix' => '<div id="prepend_div">Something will be prepended to this div. </div>',
];
......@@ -187,7 +188,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t("AJAX 'remove': Click to remove text"),
'#type' => 'submit',
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_remove_callback',
'callback' => [Callbacks::class, 'advancedCommandsRemoveCallback'],
],
'#suffix' => '<div id="remove_div"><div id="remove_text">text to be removed</div></div>',
];
......@@ -197,7 +198,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'submit',
'#value' => $this->t("AJAX 'restripe' command"),
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_restripe_callback',
'callback' => [Callbacks::class, 'advancedCommandsRestripeCallback'],
],
'#suffix' => '<div id="restripe_div">
<table id="restripe_table" style="border: 1px solid black" >
......@@ -213,7 +214,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'submit',
'#value' => $this->t("AJAX 'settings' command"),
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_settings_callback',
'callback' => [Callbacks::class, 'advancedCommandsSettingsCallback'],
],
];
......@@ -222,7 +223,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'submit',
'#value' => $this->t("AJAX 'add_css' command"),
'#ajax' => [
'callback' => 'ajax_forms_test_advanced_commands_add_css_callback',
'callback' => [Callbacks::class, 'advancedCommandsAddCssCallback'],
],
];
......
......@@ -26,7 +26,6 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$object = new Callbacks();
$form['image_button'] = [
'#type' => 'image_button',
'#name' => 'image_button',
......@@ -34,7 +33,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#attributes' => ['alt' => $this->t('Edit')],
'#op' => 'edit',
'#ajax' => [
'callback' => [$object, 'imageButtonCallback'],
'callback' => [Callbacks::class, 'imageButtonCallback'],
],
'#suffix' => '<div id="ajax_image_button_result">Image button not pressed yet.</div>',
];
......
......@@ -4,6 +4,7 @@
namespace Drupal\ajax_forms_test\Form;
use Drupal\ajax_forms_test\Callbacks;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -40,7 +41,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#value' => $this->t('Submit'),
'#ajax' => [
'wrapper' => 'ajax-forms-test-lazy-load-ajax-wrapper',
'callback' => 'ajax_forms_test_lazy_load_form_ajax',
'callback' => [Callbacks::class, 'lazyLoadFormAjax'],
],
'#prefix' => '<div id="ajax-forms-test-lazy-load-ajax-wrapper"></div>',
];
......
......@@ -26,8 +26,6 @@ public function getFormId() {
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$object = new Callbacks();
$form = [];
$form['select'] = [
'#title' => $this->t('Color'),
......@@ -38,7 +36,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'blue' => 'blue',
],
'#ajax' => [
'callback' => [$object, 'selectCallback'],
'callback' => [Callbacks::class, 'selectCallback'],
],
'#suffix' => '<div id="ajax_selected_color">No color yet selected</div>',
];
......@@ -47,7 +45,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'checkbox',
'#title' => $this->t('Test checkbox'),
'#ajax' => [
'callback' => [$object, 'checkboxCallback'],
'callback' => [Callbacks::class, 'checkboxCallback'],
],
'#suffix' => '<div id="ajax_checkbox_value">No action yet</div>',
];
......@@ -87,7 +85,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'checkbox',
'#title' => $this->t('AJAX checkbox in a group'),
'#ajax' => [
'callback' => [$object, 'checkboxGroupCallback'],
'callback' => [Callbacks::class, 'checkboxGroupCallback'],
'wrapper' => 'checkbox-wrapper',
],
],
......@@ -101,7 +99,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#group' => 'nested_group',
'#title' => $this->t('AJAX checkbox in a nested group'),
'#ajax' => [
'callback' => [$object, 'checkboxGroupCallback'],
'callback' => [Callbacks::class, 'checkboxGroupCallback'],
'wrapper' => 'checkbox-wrapper',
],
],
......
......@@ -4,6 +4,7 @@
namespace Drupal\ajax_forms_test\Form;
use Drupal\ajax_forms_test\Callbacks;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
......@@ -31,7 +32,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'textfield',
'#default_value' => $form_state->getValue('driver_text', ''),
'#ajax' => [
'callback' => 'ajax_forms_test_validation_form_callback',
'callback' => [Callbacks::class, 'validationFormCallback'],
'wrapper' => 'message_area',
'method' => 'replaceWith',
],
......@@ -44,7 +45,7 @@ public function buildForm(array $form, FormStateInterface $form_state) {
'#type' => 'number',
'#default_value' => $form_state->getValue('driver_number', ''),
'#ajax' => [
'callback' => 'ajax_forms_test_validation_number_form_callback',
'callback' => [Callbacks::class, 'validationNumberFormCallback'],
'wrapper' => 'message_area_number',
'method' => 'replaceWith',
],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment