Changeset 52103 for trunk/src/wp-includes/blocks
- Timestamp:
- 11/10/2021 05:59:55 AM (3 years ago)
- Location:
- trunk/src/wp-includes/blocks
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/blocks/column/block.json
r52042 r52103 18 18 }, 19 19 "templateLock": { 20 "type": "string",20 "type": [ "string", "boolean" ], 21 21 "enum": [ "all", "insert", false ] 22 22 } -
trunk/src/wp-includes/blocks/cover/block.json
r52042 r52103 68 68 }, 69 69 "templateLock": { 70 "type": "string",70 "type": [ "string", "boolean" ], 71 71 "enum": [ "all", "insert", false ] 72 72 } -
trunk/src/wp-includes/blocks/group/block.json
r52042 r52103 13 13 }, 14 14 "templateLock": { 15 "type": "string",15 "type": [ "string", "boolean" ], 16 16 "enum": [ "all", "insert", false ] 17 17 } -
trunk/src/wp-includes/blocks/navigation.php
r52069 r52103 84 84 85 85 return $font_sizes; 86 }87 88 /**89 * Returns the menu items for a WordPress menu location.90 *91 * @param string $location The menu location.92 * @return array Menu items for the location.93 */94 function gutenberg_get_menu_items_at_location( $location ) {95 if ( empty( $location ) ) {96 return;97 }98 99 // Build menu data. The following approximates the code in100 // `wp_nav_menu()` and `gutenberg_output_block_nav_menu`.101 102 // Find the location in the list of locations, returning early if the103 // location can't be found.104 $locations = get_nav_menu_locations();105 if ( ! isset( $locations[ $location ] ) ) {106 return;107 }108 109 // Get the menu from the location, returning early if there is no110 // menu or there was an error.111 $menu = wp_get_nav_menu_object( $locations[ $location ] );112 if ( ! $menu || is_wp_error( $menu ) ) {113 return;114 }115 116 $menu_items = wp_get_nav_menu_items( $menu->term_id, array( 'update_post_term_cache' => false ) );117 _wp_menu_item_classes_by_context( $menu_items );118 119 return $menu_items;120 }121 122 /**123 * Sorts a standard array of menu items into a nested structure keyed by the124 * id of the parent menu.125 *126 * @param array $menu_items Menu items to sort.127 * @return array An array keyed by the id of the parent menu where each element128 * is an array of menu items that belong to that parent.129 */130 function gutenberg_sort_menu_items_by_parent_id( $menu_items ) {131 $sorted_menu_items = array();132 foreach ( (array) $menu_items as $menu_item ) {133 $sorted_menu_items[ $menu_item->menu_order ] = $menu_item;134 }135 unset( $menu_items, $menu_item );136 137 $menu_items_by_parent_id = array();138 foreach ( $sorted_menu_items as $menu_item ) {139 $menu_items_by_parent_id[ $menu_item->menu_item_parent ][] = $menu_item;140 }141 142 return $menu_items_by_parent_id;143 }144 145 /**146 * Turns menu item data into a nested array of parsed blocks147 *148 * @param array $menu_items An array of menu items that represent149 * an individual level of a menu.150 * @param array $menu_items_by_parent_id An array keyed by the id of the151 * parent menu where each element is an152 * array of menu items that belong to153 * that parent.154 * @return array An array of parsed block data.155 */156 function gutenberg_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {157 if ( empty( $menu_items ) ) {158 return array();159 }160 161 $blocks = array();162 163 foreach ( $menu_items as $menu_item ) {164 $class_name = ! empty( $menu_item->classes ) ? implode( ' ', (array) $menu_item->classes ) : null;165 $id = ( null !== $menu_item->object_id && 'custom' !== $menu_item->object ) ? $menu_item->object_id : null;166 $opens_in_new_tab = null !== $menu_item->target && '_blank' === $menu_item->target;167 $rel = ( null !== $menu_item->xfn && '' !== $menu_item->xfn ) ? $menu_item->xfn : null;168 $kind = null !== $menu_item->type ? str_replace( '_', '-', $menu_item->type ) : 'custom';169 170 $block = array(171 'blockName' => 'core/navigation-link',172 'attrs' => array(173 'className' => $class_name,174 'description' => $menu_item->description,175 'id' => $id,176 'kind' => $kind,177 'label' => $menu_item->title,178 'opensInNewTab' => $opens_in_new_tab,179 'rel' => $rel,180 'title' => $menu_item->attr_title,181 'type' => $menu_item->object,182 'url' => $menu_item->url,183 ),184 );185 186 $block['innerBlocks'] = gutenberg_parse_blocks_from_menu_items(187 isset( $menu_items_by_parent_id[ $menu_item->ID ] )188 ? $menu_items_by_parent_id[ $menu_item->ID ]189 : array(),190 $menu_items_by_parent_id191 );192 193 $blocks[] = $block;194 }195 196 return $blocks;197 86 } 198 87 … … 355 244 $responsive_container_markup = sprintf( 356 245 '<button aria-expanded="false" aria-haspopup="true" aria-label="%3$s" class="%6$s" data-micromodal-trigger="modal-%1$s"><svg width="24" height="24" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" role="img" aria-hidden="true" focusable="false"><rect x="4" y="7.5" width="16" height="1.5" /><rect x="4" y="15" width="16" height="1.5" /></svg></button> 357 <div class="%5$s" id="modal-%1$s" aria-hidden="true">246 <div class="%5$s" id="modal-%1$s"> 358 247 <div class="wp-block-navigation__responsive-close" tabindex="-1" data-micromodal-close> 359 248 <div class="wp-block-navigation__responsive-dialog" role="dialog" aria-modal="true" aria-labelledby="modal-%1$s-title" > -
trunk/src/wp-includes/blocks/navigation/block.json
r52069 r52103 115 115 "allowInheriting": false, 116 116 "default": { 117 "type": "flex" 117 "type": "flex", 118 "setCascadingProperties": true 118 119 } 119 120 } -
trunk/src/wp-includes/blocks/navigation/view.asset.php
r52069 r52103 1 <?php return array('dependencies' => array(), 'version' => '8 6538493346805d860c94eb70dd1323d');1 <?php return array('dependencies' => array(), 'version' => '8591fc81d18e61a0f33b213b1fe35e52'); -
trunk/src/wp-includes/blocks/navigation/view.min.asset.php
r52069 r52103 1 <?php return array('dependencies' => array(), 'version' => ' 7b2c5174a07c417dc3db6f1d9a9c3f78');1 <?php return array('dependencies' => array(), 'version' => '4942262e50480536aae4cd504a13f19c');
Note: See TracChangeset
for help on using the changeset viewer.