Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/Form/Control/Callbacks/RecalculateCallback.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,23 @@
final class RecalculateCallback {

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

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

return $response;
}
Expand Down