$attrs Resolved attribute values (unused here). * @return array{image: string|null} */ protected function viewData( Product $product, array $attrs ): array { unset( $attrs ); return array( 'image' => $this->image( (int) ( $product->settings()['main_image'] ?? 0 ) ), ); } /** * The block is degenerate when the product has no resolvable main image. * * @param array $data The reduced view data. * @return bool */ protected function viewDataIsEmpty( array $data ): bool { return null === ( $data['image'] ?? null ); } /** * Sample image data for an editor preview. * * @param Product $product The resolved product (unused; the tile is fixed). * @param array $attrs Resolved attribute values (unused here). * @return array{image: string} */ protected function sampleViewData( Product $product, array $attrs ): array { unset( $product, $attrs ); return array( 'image' => SamplePreview::placeholderTile( 'releasecart-product-images__img', __( 'Sample product image', 'releasecart' ) ), ); } /** * Resolve an attachment to responsive image markup. * * @param int $id The attachment id. * @return string|null */ private function image( int $id ): ?string { if ( $id <= 0 ) { return null; } $html = wp_get_attachment_image( $id, self::IMAGE_SIZE, false, array( 'class' => 'releasecart-product-images__img' ) ); return is_string( $html ) && '' !== $html ? $html : null; } }