Automattic\WooCommerce\Blocks\Assets
AssetDataRegistry::hydrate_data_from_api_request
Hydrate some data from the API.
Method of the class: AssetDataRegistry{}
No Hooks.
Returns
null. Nothing (null).
Usage
$AssetDataRegistry = new AssetDataRegistry(); $AssetDataRegistry->hydrate_data_from_api_request( $key, $path, $check_key_exists );
- $key(string) (required)
- The key used to reference the data being registered.
- $path(string) (required)
- REST API path to preload.
- $check_key_exists(true|false)
- Deprecated. Duplicate data will be ignored if the key exists.
Default:false
AssetDataRegistry::hydrate_data_from_api_request() AssetDataRegistry::hydrate data from api request code WC 11.1.2
public function hydrate_data_from_api_request( $key, $path, $check_key_exists = false ) { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundAfterLastUsed -- Deprecated parameter kept for backwards compatibility.
if ( 3 <= func_num_args() ) {
wc_deprecated_argument(
__METHOD__ . '()',
'8.9',
'The $check_key_exists parameter is no longer used: all duplicate data will be ignored if the key exists by default'
);
}
$this->add(
$key,
function () use ( $path ) {
if ( isset( $this->preloaded_api_requests[ $path ], $this->preloaded_api_requests[ $path ]['body'] ) ) {
return $this->preloaded_api_requests[ $path ]['body'];
}
$response = Package::container()->get( Hydration::class )->get_rest_api_response_data( $path );
return $response['body'] ?? '';
}
);
}