Associative array of resource data. */ protected function prepare_resource_fields( $entity, array $fields ): array { $data = array(); foreach ( $fields as $field ) { $data[ $field ] = $entity->get_field_value( $field ); } return $data; } /** * Prepares links for the given resource. * * @since 0.5.0 * * @param History_Entity $entity The entity to prepare links for. * @return array> Links for the given resource. */ protected function prepare_resource_links( $entity ): array { return array( 'self' => array( 'href' => $this->get_route_url( str_replace( array( '(?P[\w-]+)', '(?P[\w-]+)', ), array( $entity->get_field_value( 'feature' ), $entity->get_field_value( 'slug' ), ), History_Get_REST_Route::BASE ) ), ), 'collection' => array( 'href' => $this->get_collection_route_url( array( 'feature' => $entity->get_field_value( 'feature' ) ) ), ), ); } /** * Returns the full URL to the resource's collection route. * * @since 0.5.0 * * @param array $params Optional. Current request parameters. Default empty array. * @return string Full collection route URL. */ protected function get_collection_route_url( array $params = array() ): string { return $this->get_route_url( str_replace( '(?P[\w-]+)', $params['feature'] ?? '', History_List_REST_Route::BASE ) ); } /** * Returns the internal resource schema definition. * * @since 0.5.0 * * @return array Internal resource schema definition. */ protected function schema(): array { return array_merge( array( '$schema' => 'http://json-schema.org/draft-04/schema#', 'title' => 'history', ), History::get_json_schema() ); } }