Skip to content

Commit 3d26e54

Browse files
author
Dominic Tubach
committed
Allow other modules to have AJAX callbacks with recalculation
1 parent 7563607 commit 3d26e54

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Form/Control/Callbacks/RecalculateCallback.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@
2828
final class RecalculateCallback {
2929

3030
/**
31-
* @phpstan-param array<int|string, mixed> $form $form
31+
* This method may be used by other modules to have custom AJAX callbacks that
32+
* sill can perform recalculation.
3233
*/
33-
public static function onChange(array &$form, FormStateInterface $formState): AjaxResponse {
34+
public static function addAjaxCommands(AjaxResponse $response, FormStateInterface $formState): void {
3435
/** @var \Drupal\json_forms\Form\AbstractJsonFormsForm $formObject */
3536
$formObject = $formState->getFormObject();
3637
$newData = FieldNameUtil::toFormData($formObject->calculateData($formState));
3738
$oldData = $formState->getValues();
39+
RecalculateCallbackUtil::addAjaxCommands($response, $formState, $oldData, $newData);
40+
}
3841

42+
/**
43+
* @phpstan-param array<int|string, mixed> $form $form
44+
*/
45+
public static function onChange(array &$form, FormStateInterface $formState): AjaxResponse {
3946
$response = new AjaxResponse();
40-
RecalculateCallbackUtil::addAjaxCommands($response, $formState, $oldData, $newData);
47+
self::addAjaxCommands($response, $formState);
4148

4249
return $response;
4350
}

0 commit comments

Comments
 (0)