entryService = $entryService; } /** * @param WP_REST_Request $data * * @return WP_REST_Response * * @throws NotFoundException * @throws InvalidArgumentException|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 entry ID is provided if (empty($data->get_params())) { throw new InvalidArgumentException( BackendStrings::getExceptionStrings()['entry_id_required'] ); } $entryId = Sanitizer::sanitizeId($data->get_param('id')); $entry = $this->entryService->getEntry($entryId); $fields = $this->entryService->getFieldsByEntryId($entryId); $fieldsMap = []; foreach ($fields as $field) { $fieldsMap[] = $field->toArray(); } return new WP_REST_Response([ 'entry' => $entry->toArray(), 'fields' => $fieldsMap, ], 200); } }