formService = $formService; $this->fieldService = $fieldService; $this->confirmationService = $confirmationService; } /** * @param WP_REST_Request $data * @return WP_REST_Response * @throws NotFoundException * @throws InvalidArgumentException|ForbiddenException|ValidationException * @throws QueryExecutionException */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // Check if the form ID is provided if (empty($data->get_params())) { throw new InvalidArgumentException( BackendStrings::getExceptionStrings()['invalid_request_data'] ); } // Sanitize the input data $formId = Sanitizer::sanitizeId($data->get_param('id')); $form = $this->formService->getFormById($formId); // Use the service to get fields with options $fieldsMap = $this->fieldService->getAllFieldsWithOptions($form->getId()); $form->setFields($fieldsMap); $confirmationsArr = $this->confirmationService->getConfirmationsById($formId); $confirmations = []; foreach ($confirmationsArr as $confirmation) { $confirmations[] = $confirmation->toArray(); } return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => array_merge($form->toArray(), ['confirmationId' => $confirmations[0]['id']]) ], 200); } }