Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks

Video::transform_to_cover_blockprivateWC 1.0

Transform a video block into a cover block structure.

Method of the class: Video{}

No Hooks.

Returns

Array. Cover block structure.

Usage

// private - for code of main (parent) class only
$result = $this->transform_to_cover_block( $video_block, $poster_url ): array;
$video_block(array) (required)
Original video block.
$poster_url(string) (required)
Poster URL to use as background.

Video::transform_to_cover_block() code WC 10.5.0

private function transform_to_cover_block( array $video_block, string $poster_url ): array {
	$block_attrs   = $video_block['attrs'] ?? array();
	$block_content = $video_block['innerHTML'] ?? '';

	// Extract video URL from block content, fall back to post URL.
	// Priority: 1) Video URL (if found), 2) Post permalink (fallback).
	$video_url = $this->extract_video_url( $block_content );
	$link_url  = ! empty( $video_url ) ? $video_url : $this->get_current_post_url();

	return array(
		'blockName'   => 'core/cover',
		'attrs'       => array(
			'url'       => $poster_url,
			'minHeight' => '390px', // Custom attribute for video blocks.
		),
		'innerBlocks' => array(
			array(
				'blockName'    => 'core/html',
				'attrs'        => array(),
				'innerBlocks'  => array(),
				'innerHTML'    => $this->create_play_button_html( $link_url ),
				'innerContent' => array( $this->create_play_button_html( $link_url ) ),
			),
		),
		'innerHTML'   => $block_content,
	);
}