Skip to content

Commit

Permalink
Merge pull request #139 from NMantek/fix/jsonStep
Browse files Browse the repository at this point in the history
Fix wrong step value in json
  • Loading branch information
NMantek authored Oct 16, 2024
2 parents 7c12c41 + 144211a commit eb359d9
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions Classes/Controller/FormController.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,27 +432,24 @@ public function formAction(): ResponseInterface {
$this->jsonResponse->redirectCode = $response->getStatusCode();
}

return $this->jsonResponse(json_encode($this->jsonResponse) ?: '{}');
return $this->jsonResponse($this->prepareJsonResponse());
}

return $response;
}
if ('json' == $this->formConfig->responseType) {
$this->jsonResponse->success = true;

return $this->jsonResponse(json_encode($this->jsonResponse) ?: '{}');
return $this->jsonResponse($this->prepareJsonResponse());
}
}
}
}

if ('json' == $this->formConfig->responseType) {
$this->jsonResponse->fieldsErrors = $this->formConfig->fieldsErrors;
$this->jsonResponse->fieldSets = $this->formConfig->fieldSets;
$this->jsonResponse->formErrors = $this->formConfig->formErrors;
$this->jsonResponse->formValues = $this->formConfig->formValues;
$this->prepareFormSets();

return $this->jsonResponse(json_encode($this->jsonResponse) ?: '{}');
if ('json' == $this->formConfig->responseType) {
return $this->jsonResponse($this->prepareJsonResponse());
}

return new RedirectResponse(
Expand All @@ -463,17 +460,9 @@ public function formAction(): ResponseInterface {
$this->prepareFormSets();

if ('json' == $this->formConfig->responseType) {
$this->jsonResponse->steps = $this->formConfig->steps;
$this->jsonResponse->fieldsErrors = $this->formConfig->fieldsErrors;
$this->jsonResponse->fieldSets = $this->formConfig->fieldSets;
$this->jsonResponse->fileUpload = $this->formConfig->fileUpload;
$this->jsonResponse->formErrors = $this->formConfig->formErrors;
$this->jsonResponse->formUploads = $this->formConfig->formUploads;
$this->jsonResponse->formValues = $this->formConfig->formValues;

$this->formConfig->processDebugLog();

return $this->jsonResponse(json_encode($this->jsonResponse) ?: '{}');
return $this->jsonResponse($this->prepareJsonResponse());
}

foreach ($this->formConfig->steps[$this->formConfig->step]->validators as $validator) {
Expand Down Expand Up @@ -645,7 +634,7 @@ private function initJsonResponse(): void {
$this->jsonResponse->formValuesPrefix = $this->formConfig->formValuesPrefix;
$this->jsonResponse->requiredFields = $this->formConfig->requiredFields;
$this->jsonResponse->selectsOptions = $this->formConfig->selectsOptions;
$this->jsonResponse->step = $this->formConfig->step;
$this->jsonResponse->steps = $this->formConfig->steps;
}
}

Expand Down Expand Up @@ -732,6 +721,18 @@ private function prepareFormSets(): void {
$this->formConfig->fieldSets[] = new FieldSetModel('step', (string) $this->formConfig->step);
}

private function prepareJsonResponse(): string {
$this->jsonResponse->fieldsErrors = $this->formConfig->fieldsErrors;
$this->jsonResponse->fieldSets = $this->formConfig->fieldSets;
$this->jsonResponse->formErrors = $this->formConfig->formErrors;
$this->jsonResponse->formValues = $this->formConfig->formValues;
$this->jsonResponse->fileUpload = $this->formConfig->fileUpload;
$this->jsonResponse->formUploads = $this->formConfig->formUploads;
$this->jsonResponse->step = $this->formConfig->step;

return json_encode($this->jsonResponse) ?: '{}';
}

/**
* @param array<int|string, mixed> $uploadsName
* @param array<int|string, mixed> $uploadsTempName
Expand Down

0 comments on commit eb359d9

Please sign in to comment.