Skip to content

Commit

Permalink
feat: pass color settings from group and column blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
adekbadek committed Apr 21, 2020
1 parent 125f18c commit 9f8a73e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions includes/class-newspack-newsletters-renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ function ( $key ) use ( &$attrs ) {
* @param WP_Block $block The block.
* @param bool $is_in_column Whether the component is a child of a column component.
* @param bool $is_in_group Whether the component is a child of a group component.
* @param array $default_attrs Default attributes for the component.
* @return string MJML component.
*/
private static function render_mjml_component( $block, $is_in_column = false, $is_in_group = false ) {
private static function render_mjml_component( $block, $is_in_column = false, $is_in_group = false, $default_attrs = [] ) {
$block_name = $block['blockName'];
$attrs = $block['attrs'];
$inner_blocks = $block['innerBlocks'];
Expand All @@ -176,7 +177,7 @@ private static function render_mjml_component( $block, $is_in_column = false, $i
}

$block_mjml_markup = '';
$attrs = self::process_attributes( $attrs );
$attrs = self::process_attributes( array_merge( $default_attrs, $attrs ) );

// Default attributes for the section which will envelop the mj-column.
$section_attrs = array_merge(
Expand Down Expand Up @@ -414,7 +415,7 @@ private static function render_mjml_component( $block, $is_in_column = false, $i

$markup = '<mj-column ' . self::array_to_attributes( $column_attrs ) . '>';
foreach ( $inner_blocks as $block ) {
$markup .= self::render_mjml_component( $block, true );
$markup .= self::render_mjml_component( $block, true, false, $default_attrs );
}
$block_mjml_markup = $markup . '</mj-column>';
break;
Expand All @@ -423,9 +424,12 @@ private static function render_mjml_component( $block, $is_in_column = false, $i
* Columns block.
*/
case 'core/columns':
if ( isset( $attrs['color'] ) ) {
$default_attrs['color'] = $attrs['color'];
}
$markup = '';
foreach ( $inner_blocks as $block ) {
$markup .= self::render_mjml_component( $block, true );
$markup .= self::render_mjml_component( $block, true, false, $default_attrs );
}
$block_mjml_markup = $markup;
break;
Expand All @@ -445,9 +449,14 @@ private static function render_mjml_component( $block, $is_in_column = false, $i
* Group block.
*/
case 'core/group':
// There's no color attribute on mj-wrapper, so it has to be passed to children.
// https://github.com/mjmlio/mjml/issues/1881 .
if ( isset( $attrs['color'] ) ) {
$default_attrs['color'] = $attrs['color'];
}
$markup = '<mj-wrapper ' . self::array_to_attributes( $attrs ) . '>';
foreach ( $inner_blocks as $block ) {
$markup .= self::render_mjml_component( $block, false, true );
$markup .= self::render_mjml_component( $block, false, true, $default_attrs );
}
$block_mjml_markup = $markup . '</mj-wrapper>';
break;
Expand Down

0 comments on commit 9f8a73e

Please sign in to comment.