Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryLargeImageNextPrevious::render()protectedWC 1.0

Include and render the block.

Method of the class: ProductGalleryLargeImageNextPrevious{}

No Hooks.

Return

String. Rendered block type output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
Default: empty array
$content(string) (required)
Block content.
Default: empty string
$block(WP_Block) (required)
Block instance.

ProductGalleryLargeImageNextPrevious::render() code WC 8.9.0

protected function render( $attributes, $content, $block ) {
	$post_id = $block->context['postId'];
	if ( ! isset( $post_id ) ) {
		return '';
	}

	$product = wc_get_product( $post_id );

	$product_gallery = $product->get_gallery_image_ids();

	if ( empty( $product_gallery ) ) {
		return null;
	}

	$context     = $block->context;
	$prev_button = $this->get_button( 'previous', $context );
	$p           = new \WP_HTML_Tag_Processor( $prev_button );

	if ( $p->next_tag() ) {
		$p->set_attribute(
			'data-wc-on--click',
			'actions.selectPreviousImage'
		);
		$p->set_attribute(
			'aria-label',
			__( 'Previous image', 'woocommerce' )
		);
		$prev_button = $p->get_updated_html();
	}

	$next_button = $this->get_button( 'next', $context );
	$p           = new \WP_HTML_Tag_Processor( $next_button );

	if ( $p->next_tag() ) {
		$p->set_attribute(
			'data-wc-on--click',
			'actions.selectNextImage'
		);
		$p->set_attribute(
			'aria-label',
			__( 'Next image', 'woocommerce' )
		);
		$next_button = $p->get_updated_html();
	}

	$alignment_class = isset( $attributes['layout']['verticalAlignment'] ) ? 'is-vertically-aligned-' . $attributes['layout']['verticalAlignment'] : '';
	$position_class  = 'wc-block-product-gallery-large-image-next-previous--' . $this->get_class_suffix( $context );

	return strtr(
		'<div
			class="wc-block-product-gallery-large-image-next-previous wp-block-woocommerce-product-gallery-large-image-next-previous {alignment_class}"
			data-wc-interactive=\'{data_wc_interactive}\'
		>
			<div class="wc-block-product-gallery-large-image-next-previous-container {position_class}">
				{prev_button}
				{next_button}
			</div>
	</div>',
		array(
			'{prev_button}'         => $prev_button,
			'{next_button}'         => $next_button,
			'{alignment_class}'     => $alignment_class,
			'{position_class}'      => $position_class,
			'{data_wc_interactive}' => wp_json_encode( array( 'namespace' => 'woocommerce/product-gallery' ), JSON_NUMERIC_CHECK ),
		)
	);
}