Automattic\WooCommerce\EmailEditor\Integrations\Core\Renderer\Blocks
Image::apply_image_border_style
Apply border style to the image.
Method of the class: Image{}
No Hooks.
Returns
null. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->apply_image_border_style( $block_content, $parsed_block, $class_name ): string;
- $block_content(string) (required)
- Block content.
- $parsed_block(array) (required)
- Parsed block.
- $class_name(string) (required)
- Class name.
Image::apply_image_border_style() Image::apply image border style code WC 10.6.2
private function apply_image_border_style( string $block_content, array $parsed_block, string $class_name ): string {
// Getting individual border properties.
$border_styles = wp_style_engine_get_styles( array( 'border' => $parsed_block['attrs']['style']['border'] ?? array() ) );
$border_styles = $border_styles['declarations'] ?? array();
if ( ! empty( $border_styles ) ) {
$border_styles['border-style'] = 'solid';
$border_styles['box-sizing'] = 'border-box';
}
// Apply border to the dedicated border cell wrapper, not the outer image cell.
// This ensures borders stay tight around the image on mobile when the outer wrapper becomes 100% width.
$border_element_tag = array(
'tag_name' => 'td',
'class_name' => 'email-image-border-cell',
);
$content_with_border_styles = $this->add_style_to_element( $block_content, $border_element_tag, \WP_Style_Engine::compile_css( $border_styles, '' ) );
// Remove border styles from the image HTML tag.
$content_with_border_styles = $this->remove_style_attribute_from_element( $content_with_border_styles, array( 'tag_name' => 'img' ), 'border-style' );
$content_with_border_styles = $this->remove_style_attribute_from_element( $content_with_border_styles, array( 'tag_name' => 'img' ), 'border-width' );
$content_with_border_styles = $this->remove_style_attribute_from_element( $content_with_border_styles, array( 'tag_name' => 'img' ), 'border-color' );
$content_with_border_styles = $this->remove_style_attribute_from_element( $content_with_border_styles, array( 'tag_name' => 'img' ), 'border-radius' );
// Add Border related classes to proper element. This is required for inlined border-color styles when defined via class.
$border_classes = array_filter(
explode( ' ', $class_name ),
function ( $class_name ) {
return strpos( $class_name, 'border' ) !== false;
}
);
$html = new \WP_HTML_Tag_Processor( $content_with_border_styles );
if ( $html->next_tag( $border_element_tag ) ) {
$class_name = $html->get_attribute( 'class' ) ?? '';
$border_classes[] = $class_name;
$html->set_attribute( 'class', implode( ' ', $border_classes ) );
}
return $html->get_updated_html();
}