entryService = $entryService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * @throws ForbiddenException * @throws InvalidArgumentException * @throws ValidationException */ 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 searchEntries method $entriesArr = $this->entryService->getEntryManager()->searchEntries($params); // Map the data to Entry entities $entries = array_map(function ($entryData) { $entryEntity = EntryFactory::create($entryData); return $entryEntity->toArray(); }, $entriesArr['data']); $filterCount = $this->entryService->getEntryManager()->getFilterCount($params); // Pass `true` to retrieve raw field values for the result table. $entryFields = $this->entryService->getEntryFieldManager()->getEntryFields($entriesArr['data'], true); $formIdToName = $entriesArr['formIdToName'] ?? []; // Return the response with data and meta return new WP_REST_Response([ 'message' => BackendStrings::getCommonStrings()['ok'], 'data' => [ 'data' => $entries, 'meta' => $entriesArr['meta'] ?? [], 'filterCount' => $filterCount, 'entryFields' => $entryFields, 'formIdToName' => $formIdToName, ], ], 200); } }