Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryLargeImage::renderprotectedWC 1.0

Include and render the block.

Метод класса: ProductGalleryLargeImage{}

Хуков нет.

Возвращает

Строку. Rendered block type output.

Использование

// protected - в коде основоного (родительского) или дочернего класса
$result = $this->render( $attributes, $content, $block );
$attributes(массив) (обязательный)
Block attributes.
По умолчанию: empty array
$content(строка) (обязательный)
Block content.
По умолчанию: empty string
$block(WP_Block) (обязательный)
Block instance.

Код ProductGalleryLargeImage::render() WC 10.4.3

<?php
protected function render( $attributes, $content, $block ) {
	$post_id = $block->context['postId'];

	if ( ! isset( $post_id ) ) {
		return '';
	}

	global $product;

	$previous_product = $product;
	$product          = wc_get_product( $post_id );
	if ( ! $product instanceof \WC_Product ) {
		$product = $previous_product;

		return '';
	}

	$images_html       = '';
	$inner_blocks_html = '';

	foreach ( $block->inner_blocks as $inner_block ) {
		if ( 'woocommerce/product-image' === $inner_block->name ) {
			// Product Image requires special handling because we need to render it once for each image.
			$images_html .= $this->get_main_images_html( $block->context, $product, $inner_block );
		} else {
			// For Next/Previous Buttons block, check if we have more than one image, otherwise don't render it.
			if ( 'woocommerce/product-gallery-large-image-next-previous' === $inner_block->name ) {
				$product_gallery_image_count = ProductGalleryUtils::get_product_gallery_image_count( $product );
				if ( $product_gallery_image_count <= 1 ) {
					continue;
				}
			}

			// Render all the inner blocks once each.
			$inner_block_html = (
				new WP_Block(
					$inner_block->parsed_block,
					array_merge(
						(array) $block->context,
						array( 'iapi/provider' => 'woocommerce/product-gallery' )
					),
				)
			)->render( array( 'dynamic' => true ) );

			$inner_blocks_html .= $inner_block_html;
		}
	}

	ob_start();
	?>
		<div class="wc-block-product-gallery-large-image wp-block-woocommerce-product-gallery-large-image">
			<?php // No need to use wp_kses here because the image HTML is built internally. ?>
			<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
			<?php echo $images_html; ?>
			<div class="wc-block-product-gallery-large-image__inner-blocks">
				<?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
				<?php echo $inner_blocks_html; ?>
			</div>
		</div>
	<?php
	$html = ob_get_clean();

	return $html;
}