Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ServerForm): Fix AJAX error when converting debug flags #1377

Merged
merged 2 commits into from
Nov 11, 2023
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
17 changes: 14 additions & 3 deletions src/Form/ServerForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Drupal\Core\Ajax\AjaxResponse;
use Drupal\Core\Ajax\ReplaceCommand;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Form\SubformState;
Expand Down Expand Up @@ -243,6 +244,19 @@ public function form(array $form, FormStateInterface $formState): array {
return $form;
}

/**
* {@inheritdoc}
*/
protected function copyFormValuesToEntity(EntityInterface $entity, array $form, FormStateInterface $form_state): void {
// Translate the debug flag from individual checkboxes to the enum value
// that the GraphQL library expects.
$debug_flag = $form_state->getValue('debug_flag');
if (is_array($debug_flag)) {
$form_state->setValue('debug_flag', array_sum($debug_flag));
}
parent::copyFormValuesToEntity($entity, $form, $form_state);
}

/**
* {@inheritdoc}
*
Expand Down Expand Up @@ -274,9 +288,6 @@ public function validateForm(array &$form, FormStateInterface $formState): void
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $formState): void {
// Translate the debug flag from individual checkboxes to the enum value
// that the GraphQL library expects.
$formState->setValue('debug_flag', array_sum($formState->getValue('debug_flag')));
parent::submitForm($form, $formState);

$schema = $formState->getValue('schema');
Expand Down