Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryLargeImage::update_single_image │ private │ WC 1.0

Update the single image html.

Method of the class: ProductGalleryLargeImage{}

No Hooks.

Returns

string.

Usage

// private - for code of main (parent) class only
$result = $this->update_single_image( $image_html, $context, $index );
$image_html(string) (required)
The image html.
$context(array) (required)
The block context.
$index(int) (required)
The index of the image.

ProductGalleryLargeImage::update_single_image() code WC 11.1.2

private function update_single_image( $image_html, $context, $index ) {
	$p = $this->get_product_image_processor( $image_html );

	// Bail out early if we don't find any image.
	if ( ! $p->next_tag( array( 'tag_name' => 'img' ) ) ) {
		return $image_html;
	}

	$p->set_attribute( 'tabindex', '-1' );
	$p->set_attribute( 'draggable', 'false' );
	$p->set_attribute( 'data-wp-watch', 'callbacks.toggleImageVisibility' );
	$p->set_attribute( 'data-wp-on--click', 'actions.onViewerClick' );
	$p->set_attribute( 'data-wp-on--touchstart', 'actions.onTouchStart' );
	$p->set_attribute( 'data-wp-on--touchmove', 'actions.onTouchMove' );
	$p->set_attribute( 'data-wp-on--touchend', 'actions.onTouchEnd' );

	if ( 0 === $index ) {
		$p->set_attribute( 'fetchpriority', 'high' );
		$p->set_attribute( 'loading', 'eager' );
	} else {
		$p->set_attribute( 'fetchpriority', 'low' );
		$p->set_attribute( 'loading', 'lazy' );
	}

	$img_classes = 'wc-block-woocommerce-product-gallery-large-image__image';

	if ( ! empty( $context['fullScreenOnClick'] ) ) {
		$img_classes .= ' wc-block-woocommerce-product-gallery-large-image__image--full-screen-on-click';

		$p->set_attribute( 'data-wp-on--click', 'actions.openDialog' );
	}
	if ( ! empty( $context['hoverZoom'] ) ) {
		$img_classes .= ' wc-block-woocommerce-product-gallery-large-image__image--hoverZoom';

		$p->set_attribute( 'data-wp-on--mousemove', 'actions.startZoom' );
		$p->set_attribute( 'data-wp-on--mouseleave', 'actions.resetZoom' );
	}

	$p->add_class( $img_classes );

	return $p->get_updated_html();
}