Automattic\WooCommerce\Internal\VariationGallery

ClassicVariationGalleryAdmin::render_thumbnailprivateWC 1.0

Render a single thumbnail list item.

Method of the class: ClassicVariationGalleryAdmin{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->render_thumbnail( $image_id, $is_active ): void;
$image_id(int) (required)
Attachment ID.
$is_active(true|false) (required)
Whether this thumbnail is the active/primary one.

ClassicVariationGalleryAdmin::render_thumbnail() code WC 10.9.4

<?php
private function render_thumbnail( int $image_id, bool $is_active ): void {
	$thumbnail = wp_get_attachment_image( $image_id, 'thumbnail' );
	$is_broken = '' === $thumbnail;
	$classes   = array( 'wc-variation-gallery-thumb' );

	if ( $is_active ) {
		$classes[] = 'is-active';
	}

	if ( $is_broken ) {
		$classes[] = 'is-broken';
	}

	/* translators: %d attachment ID */
	$thumb_label = sprintf( __( 'Show gallery image %d', 'woocommerce' ), $image_id );
	?>
	<li
		class="<?php echo esc_attr( implode( ' ', $classes ) ); ?>"
		data-attachment_id="<?php echo esc_attr( (string) $image_id ); ?>"
	>
		<button
			type="button"
			class="wc-variation-gallery-thumb__button"
			aria-label="<?php echo esc_attr( $thumb_label ); ?>"
		>
			<?php if ( $is_broken ) : ?>
				<span class="wc-variation-gallery-thumb__broken" aria-hidden="true">
					<span class="dashicons dashicons-format-image"></span>
				</span>
				<span class="screen-reader-text">
					<?php esc_html_e( 'Attachment file missing', 'woocommerce' ); ?>
				</span>
			<?php else : ?>
				<?php echo wp_kses_post( $thumbnail ); ?>
			<?php endif; ?>
		</button>
		<button
			type="button"
			class="wc-variation-gallery-thumb__remove"
			aria-label="<?php esc_attr_e( 'Remove image', 'woocommerce' ); ?>"
		>
			<span class="dashicons dashicons-no-alt" aria-hidden="true"></span>
		</button>
	</li>
	<?php
}