MailPoet\EmailEditor\Integrations\Core\Renderer\Blocks

Image::get_block_wrapper()privateWC 1.0

Based on MJML <mj-image> but because MJML doesn't support captions, our solution is a bit different

Method of the class: Image{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->get_block_wrapper( $parsed_block, $settings_controller, ?string $caption ): string;
$parsed_block(array) (required)
Parsed block.
$settings_controller(Settings_Controller) (required)
Settings controller.
?string $caption (required)
-

Image::get_block_wrapper() code WC 9.8.1

private function get_block_wrapper( array $parsed_block, Settings_Controller $settings_controller, ?string $caption ): string {
	$styles = array(
		'border-collapse' => 'collapse',
		'border-spacing'  => '0px',
		'font-size'       => '0px',
		'vertical-align'  => 'top',
		'width'           => '100%',
	);

	$width                             = $parsed_block['attrs']['width'] ?? '100%';
	$wrapper_width                     = ( $width && '100%' !== $width ) ? $width : 'auto';
	$wrapper_styles                    = $styles;
	$wrapper_styles['width']           = $wrapper_width;
	$wrapper_styles['border-collapse'] = 'separate'; // Needed because of border radius.

	$caption_html = '';
	if ( $caption ) {
		// When the image is not aligned, the wrapper is set to 100% width due to caption that can be longer than the image.
		$caption_width                   = isset( $parsed_block['attrs']['align'] ) ? ( $parsed_block['attrs']['width'] ?? '100%' ) : '100%';
		$caption_wrapper_styles          = $styles;
		$caption_wrapper_styles['width'] = $caption_width;
		$caption_styles                  = $this->get_caption_styles( $settings_controller, $parsed_block );
		$caption_html                    = '
      <table
        role="presentation"
        class="email-table-with-width"
        border="0"
        cellpadding="0"
        cellspacing="0"
        style="' . esc_attr( \WP_Style_Engine::compile_css( $caption_wrapper_styles, '' ) ) . '"
        width="' . esc_attr( $caption_width ) . '"
          >
        <tr>
            <td style="' . esc_attr( $caption_styles ) . '">{caption_content}</td>
         </tr>
      </table>';
	}

	$styles['width'] = '100%';
	$align           = $parsed_block['attrs']['align'] ?? 'left';

	return '
      <table
        role="presentation"
        border="0"
        cellpadding="0"
        cellspacing="0"
        style="' . esc_attr( \WP_Style_Engine::compile_css( $styles, '' ) ) . '"
        width="100%"
      >
        <tr>
          <td align="' . esc_attr( $align ) . '">
            <table
              role="presentation"
              class="email-table-with-width"
              border="0"
              cellpadding="0"
              cellspacing="0"
              style="' . esc_attr( \WP_Style_Engine::compile_css( $wrapper_styles, '' ) ) . '"
              width="' . esc_attr( $wrapper_width ) . '"
            >
              <tr>
                <td class="email-image-cell">{image_content}</td>
              </tr>
            </table>' . $caption_html . '
          </td>
        </tr>
      </table>
    ';
}