Skip to content

Commit

Permalink
Save Navigation Block data to a wp_navigation post type (#35746)
Browse files Browse the repository at this point in the history
* Explore using a template part for the navigaiton block data

Destructure attributes in nav block

Add use of template part entity

Move edit into a folder like the template part block

Initial template part selection

Render the template part inner blocks

Fix visibility of UI when placeholders are visible

Remove use of theme attribute

Rework placeholder

Revert "Remove use of theme attribute"

This reverts commit 2adbdf7.

* Register custom post type

* Save data to a navigation post type

Fix showing existing navigation post inner blocks

* Output blocks from Navigation Post on frontend

* Avoid rendering block when no navigation post is set

* Fix direct insert

* Update List View feature

* Add menu switcher

* Fix types

* Use PlaceholderPreview when loading

* Add menu naming

* Update PHP strings

* Hide post editor view

* Update more PHP strings

* Rename navigation post to navigation menu

* Add upgrade process

* Show menus in ui, but remove editor support and fix some labels

* Fix empty block edit if block uses an empty entity

* Hide wp-admin CPT view again

* Fix frontend rendering from menu entity

* Preserve inner blocks if post content is saved while upgrade warning is shown

* Skip e2e tests

* Disable navigation editor tests

* Tidy up comment
  • Loading branch information
talldan authored Oct 26, 2021
1 parent f01f5cd commit 9a58337
Show file tree
Hide file tree
Showing 22 changed files with 1,197 additions and 536 deletions.
51 changes: 51 additions & 0 deletions lib/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,3 +384,54 @@ function gutenberg_add_block_menu_item_styles_to_nav_menus( $hook ) {
}
}
add_action( 'admin_enqueue_scripts', 'gutenberg_add_block_menu_item_styles_to_nav_menus' );


/**
* Registers block editor 'wp_navigation' post type.
*/
function gutenberg_register_navigation_post_type() {
$labels = array(
'name' => __( 'Navigation Menus', 'gutenberg' ),
'singular_name' => __( 'Navigation Menu', 'gutenberg' ),
'menu_name' => _x( 'Navigation Menus', 'Admin Menu text', 'gutenberg' ),
'add_new' => _x( 'Add New', 'Navigation Menu', 'gutenberg' ),
'add_new_item' => __( 'Add New Navigation Menu', 'gutenberg' ),
'new_item' => __( 'New Navigation Menu', 'gutenberg' ),
'edit_item' => __( 'Edit Navigation Menu', 'gutenberg' ),
'view_item' => __( 'View Navigation Menu', 'gutenberg' ),
'all_items' => __( 'All Navigation Menus', 'gutenberg' ),
'search_items' => __( 'Search Navigation Menus', 'gutenberg' ),
'parent_item_colon' => __( 'Parent Navigation Menu:', 'gutenberg' ),
'not_found' => __( 'No Navigation Menu found.', 'gutenberg' ),
'not_found_in_trash' => __( 'No Navigation Menu found in Trash.', 'gutenberg' ),
'archives' => __( 'Navigation Menu archives', 'gutenberg' ),
'insert_into_item' => __( 'Insert into Navigation Menu', 'gutenberg' ),
'uploaded_to_this_item' => __( 'Uploaded to this Navigation Menu', 'gutenberg' ),
// Some of these are a bit weird, what are they for?
'filter_items_list' => __( 'Filter Navigation Menu list', 'gutenberg' ),
'items_list_navigation' => __( 'Navigation Menus list navigation', 'gutenberg' ),
'items_list' => __( 'Navigation Menus list', 'gutenberg' ),
);

$args = array(
'labels' => $labels,
'description' => __( 'Navigation menus.', 'gutenberg' ),
'public' => false,
'has_archive' => false,
'show_ui' => false,
'show_in_menu' => 'themes.php',
'show_in_admin_bar' => false,
'show_in_rest' => true,
'map_meta_cap' => true,
'rest_base' => 'navigation',
'rest_controller_class' => 'WP_REST_Posts_Controller',
'supports' => array(
'title',
'editor',
'revisions',
),
);

register_post_type( 'wp_navigation', $args );
}
add_action( 'init', 'gutenberg_register_navigation_post_type' );
38 changes: 0 additions & 38 deletions packages/block-library/src/navigation/block-navigation-list.js

This file was deleted.

3 changes: 3 additions & 0 deletions packages/block-library/src/navigation/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
],
"textdomain": "default",
"attributes": {
"navigationMenuId": {
"type": "number"
},
"orientation": {
"type": "string",
"default": "horizontal"
Expand Down
Loading

0 comments on commit 9a58337

Please sign in to comment.