Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Button::render_content
Renders the block content.
Method of the class: Button{}
No Hooks.
Returns
String.
Usage
// protected - for code of main (parent) or child class $result = $this->render_content( $block_content, $parsed_block, $rendering_context ): string;
- $block_content(string) (required)
- Block content.
- $parsed_block(array) (required)
- Parsed block.
- $rendering_context(Rendering_Context) (required)
- Rendering context.
Button::render_content() Button::render content code WC 10.7.0
protected function render_content( string $block_content, array $parsed_block, Rendering_Context $rendering_context ): string {
if ( empty( $parsed_block['innerHTML'] ) ) {
return '';
}
$dom_helper = new Dom_Document_Helper( $parsed_block['innerHTML'] );
$block_classname = $dom_helper->get_attribute_value_by_tag_name( 'div', 'class' ) ?? '';
$button_link = $dom_helper->find_element( 'a' );
if ( ! $button_link ) {
return '';
}
$button_text = $dom_helper->get_element_inner_html( $button_link ) ? $dom_helper->get_element_inner_html( $button_link ) : '';
$button_url = $button_link->getAttribute( 'href' ) ? $button_link->getAttribute( 'href' ) : '#';
$data_link_href = $button_link->getAttribute( 'data-link-href' );
$block_attributes = wp_parse_args(
$parsed_block['attrs'] ?? array(),
array(
'width' => '',
'style' => array(),
'textAlign' => 'center',
'backgroundColor' => '',
'textColor' => '',
)
);
$wrapper_styles = $this->get_wrapper_styles( $block_attributes, $rendering_context );
$link_styles = $this->get_link_styles( $block_attributes, $rendering_context );
$table_attrs = array(
'style' => 'width:' . ( $block_attributes['width'] ? '100%' : 'auto' ) . ';',
);
$cell_attrs = array(
'class' => $wrapper_styles['classnames'] . ' ' . $block_classname,
'style' => $wrapper_styles['css'],
'align' => $block_attributes['textAlign'],
'valign' => 'middle',
'role' => 'presentation',
);
$data_link_attr = $data_link_href
? sprintf( ' data-link-href="%s"', esc_attr( $data_link_href ) )
: '';
$button_content = sprintf(
'<a class="button-link %1$s" style="%2$s" href="%3$s"%4$s target="_blank">%5$s</a>',
esc_attr( $link_styles['classnames'] ),
esc_attr( $link_styles['css'] ),
esc_url( $button_url ),
$data_link_attr,
$button_text
);
return Table_Wrapper_Helper::render_table_wrapper( $button_content, $table_attrs, $cell_attrs );
}