wp/wp-includes/block-supports/layout.php
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
   578 
   578 
   579 	$outer_class_names = array();
   579 	$outer_class_names = array();
   580 
   580 
   581 	// Child layout specific logic.
   581 	// Child layout specific logic.
   582 	if ( $child_layout ) {
   582 	if ( $child_layout ) {
   583 		$container_content_class   = wp_unique_prefixed_id( 'wp-container-content-' );
   583 		/*
       
   584 		 * Generates a unique class for child block layout styles.
       
   585 		 *
       
   586 		 * To ensure consistent class generation across different page renders,
       
   587 		 * only properties that affect layout styling are used. These properties
       
   588 		 * come from `$block['attrs']['style']['layout']` and `$block['parentLayout']`.
       
   589 		 *
       
   590 		 * As long as these properties coincide, the generated class will be the same.
       
   591 		 */
       
   592 		$container_content_class = wp_unique_id_from_values(
       
   593 			array(
       
   594 				'layout'       => array_intersect_key(
       
   595 					$block['attrs']['style']['layout'] ?? array(),
       
   596 					array_flip(
       
   597 						array( 'selfStretch', 'flexSize', 'columnStart', 'columnSpan', 'rowStart', 'rowSpan' )
       
   598 					)
       
   599 				),
       
   600 				'parentLayout' => array_intersect_key(
       
   601 					$block['parentLayout'] ?? array(),
       
   602 					array_flip(
       
   603 						array( 'minimumColumnWidth', 'columnCount' )
       
   604 					)
       
   605 				),
       
   606 			),
       
   607 			'wp-container-content-'
       
   608 		);
       
   609 
   584 		$child_layout_declarations = array();
   610 		$child_layout_declarations = array();
   585 		$child_layout_styles       = array();
   611 		$child_layout_styles       = array();
   586 
   612 
   587 		$self_stretch = isset( $child_layout['selfStretch'] ) ? $child_layout['selfStretch'] : null;
   613 		$self_stretch = isset( $child_layout['selfStretch'] ) ? $child_layout['selfStretch'] : null;
   588 
   614 
   704 	$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
   730 	$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;
   705 
   731 
   706 	$class_names        = array();
   732 	$class_names        = array();
   707 	$layout_definitions = wp_get_layout_definitions();
   733 	$layout_definitions = wp_get_layout_definitions();
   708 
   734 
   709 	/*
       
   710 	 * Uses an incremental ID that is independent per prefix to make sure that
       
   711 	 * rendering different numbers of blocks doesn't affect the IDs of other
       
   712 	 * blocks. Makes the CSS class names stable across paginations
       
   713 	 * for features like the enhanced pagination of the Query block.
       
   714 	 */
       
   715 	$container_class = wp_unique_prefixed_id(
       
   716 		'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-'
       
   717 	);
       
   718 
       
   719 	// Set the correct layout type for blocks using legacy content width.
   735 	// Set the correct layout type for blocks using legacy content width.
   720 	if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
   736 	if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] || isset( $used_layout['contentSize'] ) && $used_layout['contentSize'] ) {
   721 		$used_layout['type'] = 'constrained';
   737 		$used_layout['type'] = 'constrained';
   722 	}
   738 	}
   723 
   739 
   803 
   819 
   804 		$block_gap             = isset( $global_settings['spacing']['blockGap'] )
   820 		$block_gap             = isset( $global_settings['spacing']['blockGap'] )
   805 			? $global_settings['spacing']['blockGap']
   821 			? $global_settings['spacing']['blockGap']
   806 			: null;
   822 			: null;
   807 		$has_block_gap_support = isset( $block_gap );
   823 		$has_block_gap_support = isset( $block_gap );
       
   824 
       
   825 		/*
       
   826 		 * Generates a unique ID based on all the data required to obtain the
       
   827 		 * corresponding layout style. Keeps the CSS class names the same
       
   828 		 * even for different blocks on different places, as long as they have
       
   829 		 * the same layout definition. Makes the CSS class names stable across
       
   830 		 * paginations for features like the enhanced pagination of the Query block.
       
   831 		 */
       
   832 		$container_class = wp_unique_id_from_values(
       
   833 			array(
       
   834 				$used_layout,
       
   835 				$has_block_gap_support,
       
   836 				$gap_value,
       
   837 				$should_skip_gap_serialization,
       
   838 				$fallback_gap_value,
       
   839 				$block_spacing,
       
   840 			),
       
   841 			'wp-container-' . sanitize_title( $block['blockName'] ) . '-is-layout-'
       
   842 		);
   808 
   843 
   809 		$style = wp_get_layout_style(
   844 		$style = wp_get_layout_style(
   810 			".$container_class",
   845 			".$container_class",
   811 			$used_layout,
   846 			$used_layout,
   812 			$has_block_gap_support,
   847 			$has_block_gap_support,
   957  * For themes without theme.json file, make sure
   992  * For themes without theme.json file, make sure
   958  * to restore the inner div for the group block
   993  * to restore the inner div for the group block
   959  * to avoid breaking styles relying on that div.
   994  * to avoid breaking styles relying on that div.
   960  *
   995  *
   961  * @since 5.8.0
   996  * @since 5.8.0
       
   997  * @since 6.6.1 Removed inner container from Grid variations.
   962  * @access private
   998  * @access private
   963  *
   999  *
   964  * @param string $block_content Rendered block content.
  1000  * @param string $block_content Rendered block content.
   965  * @param array  $block         Block object.
  1001  * @param array  $block         Block object.
   966  * @return string Filtered block content.
  1002  * @return string Filtered block content.
   973 	);
  1009 	);
   974 
  1010 
   975 	if (
  1011 	if (
   976 		wp_theme_has_theme_json() ||
  1012 		wp_theme_has_theme_json() ||
   977 		1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
  1013 		1 === preg_match( $group_with_inner_container_regex, $block_content ) ||
   978 		( isset( $block['attrs']['layout']['type'] ) && 'flex' === $block['attrs']['layout']['type'] )
  1014 		( isset( $block['attrs']['layout']['type'] ) && ( 'flex' === $block['attrs']['layout']['type'] || 'grid' === $block['attrs']['layout']['type'] ) )
   979 	) {
  1015 	) {
   980 		return $block_content;
  1016 		return $block_content;
   981 	}
  1017 	}
   982 
  1018 
   983 	/*
  1019 	/*