Changeset 55257 for trunk/src/wp-includes/blocks/navigation.php
- Timestamp:
- 02/07/2023 12:57:52 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/navigation.php
r55246 r55257 66 66 return $menu_items_by_parent_id; 67 67 } 68 69 /** 70 * Turns menu item data into a nested array of parsed blocks 71 * 72 * @param array $menu_items An array of menu items that represent 73 * an individual level of a menu. 74 * @param array $menu_items_by_parent_id An array keyed by the id of the 75 * parent menu where each element is an 76 * array of menu items that belong to 77 * that parent. 78 * @return array An array of parsed block data.79 */ 80 function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { 81 if ( empty( $menu_items )) {82 return array();83 }84 85 $blocks = array(); 86 87 foreach ( $menu_items as $menu_item ) { 88 $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null;89 $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id: null;90 $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;91 $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null;92 $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom';93 94 $block = array( 95 'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link',96 'attrs' => array(97 'className' => $class_name,98 'description' => $menu_item->description,99 'id' => $id,100 'kind' => $kind,101 'label' => $menu_item->title,102 'opensInNewTab' => $opens_in_new_tab,103 'rel' => $rel,104 'title' => $menu_item->attr_title,105 'type' => $menu_item->object,106 'url' => $menu_item->url,107 ),108 ) ;109 110 $block['innerBlocks'] = isset( $menu_items_by_parent_id[ $menu_item->ID ] ) 111 ? block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[ $menu_item->ID ], $menu_items_by_parent_id)112 : array();113 $block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks']);114 115 $blocks[] = $block; 116 }117 118 return $blocks; 119 }68 } 69 70 /** 71 * Turns menu item data into a nested array of parsed blocks 72 * 73 * @param array $menu_items An array of menu items that represent 74 * an individual level of a menu. 75 * @param array $menu_items_by_parent_id An array keyed by the id of the 76 * parent menu where each element is an 77 * array of menu items that belong to 78 * that parent. 79 * @return array An array of parsed block data. 80 */ 81 function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) { 82 if ( empty( $menu_items ) ) { 83 return array(); 84 } 85 86 $blocks = array(); 87 88 foreach ( $menu_items as $menu_item ) { 89 $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null; 90 $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null; 91 $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target; 92 $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null; 93 $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom'; 94 95 $block = array( 96 'blockName' => isset( $menu_items_by_parent_id[ $menu_item->ID ] ) ? 'core/navigation-submenu' : 'core/navigation-link', 97 'attrs' => array( 98 'className' => $class_name, 99 'description' => $menu_item->description, 100 'id' => $id, 101 'kind' => $kind, 102 'label' => $menu_item->title, 103 'opensInNewTab' => $opens_in_new_tab, 104 'rel' => $rel, 105 'title' => $menu_item->attr_title, 106 'type' => $menu_item->object, 107 'url' => $menu_item->url, 108 ), 109 ); 110 111 $block['innerBlocks'] = isset( $menu_items_by_parent_id[ $menu_item->ID ] ) 112 ? block_core_navigation_parse_blocks_from_menu_items( $menu_items_by_parent_id[ $menu_item->ID ], $menu_items_by_parent_id ) 113 : array(); 114 $block['innerContent'] = array_map( 'serialize_block', $block['innerBlocks'] ); 115 116 $blocks[] = $block; 117 } 118 119 return $blocks; 120 120 } 121 121 … … 875 875 876 876 add_filter( 'render_block_data', 'block_core_navigation_typographic_presets_backcompatibility' ); 877 878 /**879 * Enables animation of the block inspector for the Navigation block.880 *881 * See:882 * - https://github.com/WordPress/gutenberg/pull/46342883 * - https://github.com/WordPress/gutenberg/issues/45884884 *885 * @param array $settings Default editor settings.886 * @return array Filtered editor settings.887 */888 function block_core_navigation_enable_inspector_animation( $settings ) {889 $current_animation_settings = _wp_array_get(890 $settings,891 array( '__experimentalBlockInspectorAnimation' ),892 array()893 );894 895 $settings['__experimentalBlockInspectorAnimation'] = array_merge(896 $current_animation_settings,897 array(898 'core/navigation' =>899 array(900 'enterDirection' => 'leftToRight',901 ),902 )903 );904 905 return $settings;906 }907 908 add_filter( 'block_editor_settings_all', 'block_core_navigation_enable_inspector_animation' );
Note: See TracChangeset
for help on using the changeset viewer.