Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryThumbnails::render()protectedWC 1.0

Include and render the block.

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

Хуков нет.

Возвращает

Строку. 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.

Код ProductGalleryThumbnails::render() WC 9.6.0

protected function render( $attributes, $content, $block ) {
	if ( isset( $block->context['thumbnailsPosition'] ) && '' !== $block->context['thumbnailsPosition'] && 'off' !== $block->context['thumbnailsPosition'] ) {
		if ( ! empty( $content ) ) {
			parent::register_block_type_assets();
			$this->register_chunk_translations( [ $this->block_name ] );
			return $content;
		}

		$classes_and_styles = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes );

		$post_id = $block->context['postId'] ?? '';
		$product = wc_get_product( $post_id );

		if ( $product ) {
			$crop_images            = $block->context['cropImages'] ?? false;
			$product_gallery_images = ProductGalleryUtils::get_product_gallery_images( $post_id, 'full', array(), 'wc-block-product-gallery-thumbnails__thumbnail', $crop_images );

			if ( $product_gallery_images && count( $product_gallery_images ) > 1 ) {
				$html                 = '';
				$number_of_thumbnails = isset( $block->context['thumbnailsNumberOfThumbnails'] ) ? $block->context['thumbnailsNumberOfThumbnails'] : 3;
				$mode                 = $block->context['mode'] ?? '';
				$thumbnails_count     = 1;

				foreach ( $product_gallery_images as $product_gallery_image_html ) {
					// Limit the number of thumbnails only in the standard mode (and not in dialog).
					if ( $this->should_limit_thumbnails( $mode, $thumbnails_count, $number_of_thumbnails ) ) {
						break;
					}

					// If not in dialog and it's the last thumbnail and the number of product gallery images is greater than the number of thumbnails settings output the View All markup.
					if ( $this->should_display_view_all( $mode, $thumbnails_count, $product_gallery_images, $number_of_thumbnails ) ) {
						$remaining_thumbnails_count = count( $product_gallery_images ) - $number_of_thumbnails;
						$product_gallery_image_html = $this->inject_view_all( $product_gallery_image_html, $this->generate_view_all_html( $remaining_thumbnails_count ) );
						$html                      .= $product_gallery_image_html;
					} else {
						$processor = new \WP_HTML_Tag_Processor( $product_gallery_image_html );

						if ( $processor->next_tag( 'img' ) ) {

							$processor->set_attribute( 'data-wc-on--keydown', 'actions.onThumbnailKeyDown' );
							$processor->set_attribute( 'tabindex', '0' );
							$processor->set_attribute(
								'data-wc-on--click',
								'actions.selectImage'
							);

							$html .= $processor->get_updated_html();
						}
					}

					++$thumbnails_count;
				}

				return sprintf(
					'<div class="wc-block-product-gallery-thumbnails wp-block-woocommerce-product-gallery-thumbnails %1$s" style="%2$s" data-wc-interactive=\'%4$s\'>
						%3$s
					</div>',
					esc_attr( $classes_and_styles['classes'] ),
					esc_attr( $classes_and_styles['styles'] ),
					$html,
					wp_json_encode( array( 'namespace' => 'woocommerce/product-gallery' ), JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP )
				);
			}
		}
		return;
	}
}