Automattic\WooCommerce\Blocks\BlockTypes

ProductGalleryPager::render_pager_pages()privateWC 1.0

Renders the pager pages for the product gallery.

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

Хуков нет.

Возвращает

Строку. The rendered pager pages HTML.

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

// private - только в коде основоного (родительского) класса
$result = $this->render_pager_pages( $product_gallery_images_ids, $number_of_thumbnails, $pager_display_mode );
$product_gallery_images_ids(массив) (обязательный)
An array of image IDs for the product gallery.
$number_of_thumbnails(int) (обязательный)
The number of thumbnails to display in the pager.
$pager_display_mode(строка)
The display mode for the pager.
По умолчанию: 'dots'

Код ProductGalleryPager::render_pager_pages() WC 9.4.2

private function render_pager_pages( $product_gallery_images_ids, $number_of_thumbnails, $pager_display_mode = 'dots' ) {
	$html = '';

	foreach ( $product_gallery_images_ids as $key => $product_gallery_image_id ) {
		if ( $key >= $number_of_thumbnails ) {
			break;
		}

		$is_first_pager_item = 0 === $key;
		$pager_item          = sprintf(
			'<li class="wc-block-product-gallery-pager__pager-item %2$s"><button aria-pressed="%3$s" data-wc-bind--aria-pressed="state.pagerButtonPressed">%1$s</button></li>',
			'dots' === $pager_display_mode ? $this->get_dot_icon( $is_first_pager_item ) : $key + 1,
			$is_first_pager_item ? 'wc-block-product-gallery-pager__pager-item--is-active' : '',
			$is_first_pager_item ? 'true' : 'false'
		);

		$p = new \WP_HTML_Tag_Processor( $pager_item );

		if ( $p->next_tag() ) {
			$p->set_attribute(
				'data-wc-context',
				wp_json_encode(
					array(
						'imageId' => strval( $product_gallery_image_id ),
					),
					JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_AMP,
				)
			);
			$p->set_attribute(
				'data-wc-on--click',
				'actions.selectImage'
			);
			$p->set_attribute(
				'data-wc-class--wc-block-product-gallery-pager__pager-item--is-active',
				'state.isSelected'
			);
			$html .= $p->get_updated_html();
		}
	}

	return sprintf(
		'<ul class="wc-block-product-gallery-pager__pager">
			%1$s
		</ul>',
		$html
	);
}