Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Video::transform_to_cover_block
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() Video::transform to cover block code WC 10.8.1
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: 1) From attrs (e.g., passed by Embed renderer), 2) From content, 3) Post permalink.
$video_url = $block_attrs['videoUrl'] ?? '';
if ( empty( $video_url ) ) {
$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,
);
}