Automattic\WooCommerce\Internal\CLI\Migrator\Platforms\Webflow

WebflowMapper::normalize_image_objectprivateWC 1.0

Normalize a Webflow image object into our images-array entry, or return null if unusable.

Method of the class: WebflowMapper{}

No Hooks.

Returns

Array{original_id:String,src:String,alt:?String,is_featured:true|false}|null.

Usage

// private - for code of main (parent) class only
$result = $this->normalize_image_object( $img ): ?array;
$img(mixed) (required)
Raw Webflow image entry.

WebflowMapper::normalize_image_object() code WC 11.0.0

private function normalize_image_object( $img ): ?array {
	if ( ! is_object( $img ) ) {
		return null;
	}

	$url = isset( $img->url ) ? (string) $img->url : '';
	if ( '' === $url ) {
		return null;
	}

	$alt = isset( $img->alt ) ? (string) $img->alt : null;

	$original_id = '';
	if ( isset( $img->fileId ) && '' !== (string) $img->fileId ) { // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
		$original_id = (string) $img->fileId; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase -- Webflow API uses camelCase.
	} elseif ( isset( $img->id ) && '' !== (string) $img->id ) {
		$original_id = (string) $img->id;
	} else {
		$original_id = 'webflow-' . md5( $url );
	}

	return array(
		'original_id' => $original_id,
		'src'         => $url,
		'alt'         => $alt,
		'is_featured' => false,
	);
}