formService = $formService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * @throws ForbiddenException */ public function handle(WP_REST_Request $data): WP_REST_Response { // Verify the nonce Sanitizer::verifyNonce($data->get_header('X-WP-Nonce')); // Sanitize the filtering data $params = Sanitizer::sanitizeSearchParams($data->get_query_params()); // Call the searchForms method $formsArr = $this->formService->searchForms($params); // Map the data to an array format $forms = array_map(fn($form) => (array) $form, $formsArr['data']); $filterCount = $this->formService->getFilterCount($params['shouldGetCount']); // Return the response with data and meta return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => [ 'data' => $forms, 'meta' => $formsArr['meta'], 'filterCount' => $filterCount, ], ], 200); } }