MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks
Text::render_content()
Renders the block content.
Method of the class: Text{}
No Hooks.
Return
null
. Nothing (null).
Usage
// protected - for code of main (parent) or child class $result = $this->render_content( $block_content, $parsed_block, $settings_controller ): string;
- $block_content(string) (required)
- Block content.
- $parsed_block(array) (required)
- Parsed block.
- $settings_controller(Settings_Controller) (required)
- Settings controller.
Text::render_content() Text::render content code WC 9.8.1
protected function render_content( string $block_content, array $parsed_block, Settings_Controller $settings_controller ): string { // Do not render empty blocks. if ( empty( trim( wp_strip_all_tags( $block_content ) ) ) ) { return ''; } $block_content = $this->adjustStyleAttribute( $block_content ); $block_attributes = wp_parse_args( $parsed_block['attrs'] ?? array(), array( 'textAlign' => 'left', 'style' => array(), ) ); $html = new \WP_HTML_Tag_Processor( $block_content ); $classes = 'email-text-block'; if ( $html->next_tag() ) { /** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan $block_classes = $html->get_attribute( 'class' ) ?? ''; $classes .= ' ' . $block_classes; // remove has-background to prevent double padding applied for wrapper and inner element. $block_classes = str_replace( 'has-background', '', $block_classes ); // remove border related classes because we handle border on wrapping table cell. $block_classes = preg_replace( '/[a-z-]+-border-[a-z-]+/', '', $block_classes ); /** @var string $block_classes */ // phpcs:ignore Generic.Commenting.DocComment.MissingShort -- used for phpstan $html->set_attribute( 'class', trim( $block_classes ) ); $block_content = $html->get_updated_html(); } $block_styles = $this->get_styles_from_block( array( 'color' => $block_attributes['style']['color'] ?? array(), 'spacing' => $block_attributes['style']['spacing'] ?? array(), 'typography' => $block_attributes['style']['typography'] ?? array(), 'border' => $block_attributes['style']['border'] ?? array(), ) ); $styles = array( 'min-width' => '100%', // prevent Gmail App from shrinking the table on mobile devices. ); $styles['text-align'] = 'left'; if ( ! empty( $parsed_block['attrs']['textAlign'] ) ) { // in this case, textAlign needs to be one of 'left', 'center', 'right'. $styles['text-align'] = $parsed_block['attrs']['textAlign']; } elseif ( in_array( $parsed_block['attrs']['align'] ?? null, array( 'left', 'center', 'right' ), true ) ) { $styles['text-align'] = $parsed_block['attrs']['align']; } $compiled_styles = $this->compile_css( $block_styles['declarations'], $styles ); $table_styles = 'border-collapse: separate;'; // Needed because of border radius. return sprintf( '<table role="presentation" border="0" cellpadding="0" cellspacing="0" width="100%%" style="%1$s" > <tr> <td class="%2$s" style="%3$s" align="%4$s">%5$s</td> </tr> </table>', esc_attr( $table_styles ), esc_attr( $classes ), esc_attr( $compiled_styles ), esc_attr( $styles['text-align'] ), $block_content ); }