formService = $formService; $this->fieldService = $fieldService; $this->notificationService = $notificationService; $this->confirmationService = $confirmationService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * * @throws QueryExecutionException * @throws InvalidArgumentException * @throws NotFoundException * @throws ValidationException * @throws ForbiddenException */ 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'] ); } $formId = Sanitizer::sanitizeId($data->get_param('id')) ; $newFormId = $this->formService->duplicateForm($formId); $this->fieldService->duplicateFields($formId, $newFormId); $this->notificationService->duplicateNotifications($formId, $newFormId); $this->confirmationService->duplicateConfirmations($formId, $newFormId); return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => $this->formService->getFormById($newFormId)->toArray() ], 200); } }