Skip to content

Commit 5c31bd8

Browse files
authored
Merge pull request #111 from systopia/drop-calculation-callback-if-no-calculated-field
Drop calculation callback if no calculated field exists
2 parents 4fdebeb + 0b853d7 commit 5c31bd8

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Form/Control/Callbacks/RecalculateCallback.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ public static function addAjaxCommands(AjaxResponse $response, FormStateInterfac
3939
RecalculateCallbackUtil::addAjaxCommands($response, $formState, $oldData, $newData);
4040
}
4141

42+
/**
43+
* @param array<int|string, mixed> $element
44+
*
45+
* @return array<int|string, mixed>
46+
*/
47+
public static function processElement(array $element, FormStateInterface $formState): array {
48+
if (TRUE !== $formState->get('$calculateUsed')) {
49+
if (is_array($element['#ajax'] ?? NULL) && [static::class, 'onChange'] === $element['#ajax']['callback']) {
50+
unset($element['#ajax']);
51+
}
52+
}
53+
54+
return $element;
55+
}
56+
4257
/**
4358
* @phpstan-param array<int|string, mixed> $form $form
4459
*/

src/Form/Control/Util/BasicFormPropertiesFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ public static function createFieldProperties(ControlDefinition $definition, Form
138138
'progress' => [],
139139
'disable-refocus' => TRUE,
140140
];
141+
$form['#process'] = [
142+
[RecalculateCallback::class, 'processElement'],
143+
];
141144
}
142145

143146
$form += static::createBasicProperties($definition);

0 commit comments

Comments
 (0)