@@ -573,14 +573,72 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
573573 $ child_layout_styles = array ();
574574
575575 $ self_stretch = isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['selfStretch ' ] ) ? $ block ['attrs ' ]['style ' ]['layout ' ]['selfStretch ' ] : null ;
576+ $ self_align = isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['selfAlign ' ] ) ? $ block ['attrs ' ]['style ' ]['layout ' ]['selfAlign ' ] : null ;
577+ $ height = isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['height ' ] ) ? $ block ['attrs ' ]['style ' ]['layout ' ]['height ' ] : null ;
578+ $ width = isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['width ' ] ) ? $ block ['attrs ' ]['style ' ]['layout ' ]['width ' ] : null ;
579+
580+ $ parent_layout_type = 'default ' ;
581+ if ( isset ( $ block ['parentLayout ' ]['type ' ] ) ) {
582+ $ parent_layout_type = $ block ['parentLayout ' ]['type ' ];
583+ } elseif ( isset ( $ block ['parentLayout ' ]['default ' ]['type ' ] ) ) {
584+ $ parent_layout_type = $ block ['parentLayout ' ]['default ' ]['type ' ];
585+ }
586+
587+ // Orientation is only used for flex layouts so its default is horizontal.
588+ $ parent_orientation = isset ( $ block ['parentLayout ' ]['orientation ' ] ) ? $ block ['parentLayout ' ]['orientation ' ] : 'horizontal ' ;
589+ $ vertical_parent_layout = in_array ( $ parent_layout_type , array ( 'constrained ' , 'default ' ), true ) || ( 'flex ' === $ parent_layout_type && 'vertical ' === $ parent_orientation );
576590
591+ // Support for legacy flexSize value.
577592 if ( 'fixed ' === $ self_stretch && isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['flexSize ' ] ) ) {
578593 $ child_layout_declarations ['flex-basis ' ] = $ block ['attrs ' ]['style ' ]['layout ' ]['flexSize ' ];
579594 $ child_layout_declarations ['box-sizing ' ] = 'border-box ' ;
580595 } elseif ( 'fill ' === $ self_stretch ) {
581596 $ child_layout_declarations ['flex-grow ' ] = '1 ' ;
582597 }
583598
599+ if ( $ vertical_parent_layout ) {
600+ // Width styles.
601+ if ( 'fixed ' === $ self_align && $ width ) {
602+ $ child_layout_declarations ['max-width ' ] = $ width ;
603+ } elseif ( 'fixedNoShrink ' === $ self_align && $ width ) {
604+ $ child_layout_declarations ['width ' ] = $ width ;
605+ } elseif ( 'fill ' === $ self_align ) {
606+ $ child_layout_declarations ['align-self ' ] = 'stretch ' ;
607+ } elseif ( 'fit ' === $ self_align ) {
608+ $ child_layout_declarations ['width ' ] = 'fit-content ' ;
609+ }
610+ // Height styles.
611+ if ( 'fixed ' === $ self_stretch && $ height ) {
612+ $ child_layout_declarations ['max-height ' ] = $ height ;
613+ $ child_layout_declarations ['flex-basis ' ] = $ height ;
614+ } elseif ( 'fixedNoShrink ' === $ self_stretch && $ height ) {
615+ $ child_layout_declarations ['height ' ] = $ height ;
616+ $ child_layout_declarations ['flex-shrink ' ] = '0 ' ;
617+ $ child_layout_declarations ['flex-basis ' ] = $ height ;
618+ } elseif ( 'fill ' === $ self_stretch ) {
619+ $ child_layout_declarations ['flex-grow ' ] = '1 ' ;
620+ }
621+ } elseif ( 'grid ' !== $ parent_layout_type ) {
622+ // Width styles.
623+ if ( 'fixed ' === $ self_stretch && $ width ) {
624+ $ child_layout_declarations ['flex-basis ' ] = $ width ;
625+ } elseif ( 'fixedNoShrink ' === $ self_stretch && $ width ) {
626+ $ child_layout_declarations ['flex-shrink ' ] = '0 ' ;
627+ $ child_layout_declarations ['flex-basis ' ] = $ width ;
628+ } elseif ( 'fill ' === $ self_stretch ) {
629+ $ child_layout_declarations ['flex-grow ' ] = '1 ' ;
630+ }
631+ // Height styles.
632+ if ( 'fixed ' === $ self_align && $ height ) {
633+ $ child_layout_declarations ['max-height ' ] = $ height ;
634+ } elseif ( 'fixedNoShrink ' === $ self_align && $ height ) {
635+ $ child_layout_declarations ['height ' ] = $ height ;
636+ } elseif ( 'fill ' === $ self_align ) {
637+ $ child_layout_declarations ['align-self ' ] = 'stretch ' ;
638+ }
639+ }
640+
641+ // Grid specific styles.
584642 if ( isset ( $ block ['attrs ' ]['style ' ]['layout ' ]['columnSpan ' ] ) ) {
585643 $ column_span = $ block ['attrs ' ]['style ' ]['layout ' ]['columnSpan ' ];
586644 $ child_layout_declarations ['grid-column ' ] = "span $ column_span " ;
@@ -589,6 +647,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
589647 $ row_span = $ block ['attrs ' ]['style ' ]['layout ' ]['rowSpan ' ];
590648 $ child_layout_declarations ['grid-row ' ] = "span $ row_span " ;
591649 }
650+
592651 $ child_layout_styles [] = array (
593652 'selector ' => ". $ container_content_class " ,
594653 'declarations ' => $ child_layout_declarations ,
@@ -902,6 +961,8 @@ function ( $parsed_block, $source_block, $parent_block ) {
902961 */
903962 if ( $ parent_block && isset ( $ parent_block ->parsed_block ['attrs ' ]['layout ' ] ) ) {
904963 $ parsed_block ['parentLayout ' ] = $ parent_block ->parsed_block ['attrs ' ]['layout ' ];
964+ } elseif ( $ parent_block && isset ( $ parent_block ->block_type ->supports ['layout ' ] ) ) {
965+ $ parsed_block ['parentLayout ' ] = $ parent_block ->block_type ->supports ['layout ' ];
905966 }
906967 return $ parsed_block ;
907968 },
0 commit comments