Skip to content

Commit e22d49a

Browse files
authored
Merge 69d764f into 3cd99f7
2 parents 3cd99f7 + 69d764f commit e22d49a

34 files changed

Lines changed: 838 additions & 180 deletions

‎lib/experimental/extensible-site-editor.php‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,18 @@ function gutenberg_unregister_view_post_revisions_entity_action() {
4444
}
4545
}
4646
add_action( 'wp_entity_actions_api_init', 'gutenberg_unregister_view_post_revisions_entity_action' );
47+
48+
/**
49+
* Unregisters the "Edit" action of pages, templates, template parts, and
50+
* patterns, which WordPress core registers at priority 0. The action opens an
51+
* entity with the entity navigator its screen sets in the editor store, and
52+
* the lists of these entities in the extensible site editor set none: they
53+
* open an entity when it is clicked. The navigation list sets one, so the
54+
* action of navigation menus stays.
55+
*/
56+
function gutenberg_unregister_extensible_site_editor_entity_actions() {
57+
foreach ( array( 'page', 'wp_template', 'wp_template_part', 'wp_block' ) as $post_type ) {
58+
wp_unregister_entity_actions( 'postType', $post_type, array( 'edit-post' ) );
59+
}
60+
}
61+
add_action( 'wp_entity_actions_api_init', 'gutenberg_unregister_extensible_site_editor_entity_actions' );

‎package-lock.json‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/core-actions/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ Initial release ([#84643](https://github.com/WordPress/gutenberg/pull/84643)).
77
### New Features
88

99
- Add the `page` collection, with the "Set as homepage" and "Set as posts page" actions moved from `@wordpress/editor`. They apply to the pages with the `wp:action-set-homepage` or `wp:action-set-posts-page` REST link ([#84932](https://github.com/WordPress/gutenberg/pull/84932)).
10+
- Add the "Edit" action of pages, templates, template parts, patterns, and navigation menus to the `post_type_supports` collection, moved from `@wordpress/edit-site` and the extensible site editor. It opens the entity with the entity navigator the screen sets in the editor store.
11+
- Add the "Quick edit" action of pages to the `page` collection, moved from `@wordpress/edit-site` and the extensible site editor. It opens the quick edit form of the pages with the opener the screen sets in the editor store.

‎packages/core-actions/README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ WordPress registers them on the server through the entity actions API, like a pl
88

99
The actions of this package live in folders of `src`, one per collection:
1010

11-
- `post_type_supports`: the default actions of every post type (`delete-post`, `duplicate-post`, `move-to-trash`, `order-pages`, `permanently-delete`, `rename-post`, `reset-post`, `restore`, `view-post`, and `view-post-revisions`).
12-
- `page`: the actions pages have on top of the defaults (`set-as-homepage` and `set-as-posts-page`).
11+
- `post_type_supports`: the default actions of every post type (`delete-post`, `duplicate-post`, `edit-post`, `move-to-trash`, `order-pages`, `permanently-delete`, `rename-post`, `reset-post`, `restore`, `view-post`, and `view-post-revisions`).
12+
- `page`: the actions pages have on top of the defaults (`quick-edit`, `set-as-homepage`, and `set-as-posts-page`).
1313
- `wp_block`: the actions patterns have on top of the defaults (`duplicate-pattern` and `export-pattern`).
1414
- `wp_template_part`: the actions template parts have on top of the defaults (`duplicate-template-part`).
1515

1616
Each action has a folder named after its id, with the data of the action in `action.php` and its JavaScript parts in `action.tsx`. The `index.ts` of each collection is its script module, whose default export maps the id of each action to its JavaScript parts.
1717

1818
`src/index.php` registers the actions of each post type exposed in the REST API, on the `wp_entity_actions_api_init` action at priority 0, so a plugin hooking it at the default priority can remove or replace them:
1919

20+
- `edit-post`, for pages, templates, template parts, patterns, and navigation menus, when the user can edit them. It is only shown in the lists (its `context` is `list`), and it opens the entity the way the screen showing it does: the screen sets the function opening an entity with the `setEntityNavigator` private action of the editor store, and the action does nothing on a screen that sets none.
21+
- `quick-edit`, for pages, when the user can edit them. It is only shown in the lists, and it opens the quick edit form of the pages the way the screen listing them does: the screen sets the function opening the form with the `setQuickEditOpener` private action of the editor store, and the action does nothing on a screen that sets none.
2022
- `view-post`, for the viewable post types.
2123
- `view-post-revisions`, for the post types supporting `revisions`.
2224
- `duplicate-post`, for the post types the user can create, except templates, template parts, and patterns. Only in the Gutenberg plugin.

‎packages/core-actions/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
"@wordpress/core-data": "file:../core-data",
7676
"@wordpress/data": "file:../data",
7777
"@wordpress/dataviews": "file:../dataviews",
78+
"@wordpress/editor": "file:../editor",
7879
"@wordpress/element": "file:../element",
7980
"@wordpress/html-entities": "file:../html-entities",
8081
"@wordpress/i18n": "file:../i18n",

‎packages/core-actions/src/index.php‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717
* Registers the actions of WordPress core on each post type exposed in the
1818
* REST API, from what it supports and what the current user can do:
1919
*
20+
* - `edit-post`, for pages, templates, template parts, patterns, and
21+
* navigation menus, when the user can edit them. It opens the entity the
22+
* way the screen showing it does, so it is only shown in the lists.
23+
* - `quick-edit`, for pages, when the user can edit them. It opens the quick
24+
* edit form of the pages the way the screen showing it does, so it is only
25+
* shown in the lists.
2026
* - `view-post`, for the viewable post types.
2127
* - `view-post-revisions`, for the post types supporting `revisions`.
2228
* - `duplicate-post`, for the post types the user can create, except
@@ -49,6 +55,7 @@ function register_core_entity_actions() {
4955
$is_gutenberg = defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN;
5056
$is_block_theme = wp_is_block_theme();
5157
$design_types = array( 'wp_block', 'wp_template', 'wp_template_part' );
58+
$editable_types = array_merge( array( 'page', 'wp_navigation' ), $design_types );
5259
$definitions = array();
5360

5461
// Each file is required in its own variable scope.
@@ -70,6 +77,8 @@ function register_core_entity_actions() {
7077
// The actions of the post type, keyed by the folder of their script
7178
// module and their id, in the order they are shown.
7279
$applies = array(
80+
'post_type_supports/edit-post' => in_array( $name, $editable_types, true ) && current_user_can( $post_type->cap->edit_posts ),
81+
'page/quick-edit' => 'page' === $name && current_user_can( $post_type->cap->edit_posts ),
7382
'post_type_supports/view-post' => is_post_type_viewable( $post_type ),
7483
'post_type_supports/view-post-revisions' => post_type_supports( $name, 'revisions' ),
7584
'post_type_supports/duplicate-post' => $is_gutenberg && $can_create && ! in_array( $name, $design_types, true ),

‎packages/core-actions/src/page/index.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@
77
*/
88

99
import type { ActionScriptParts } from '../shared/types';
10+
import quickEdit from './quick-edit/action';
1011
import setAsHomepage from './set-as-homepage/action';
1112
import setAsPostsPage from './set-as-posts-page/action';
1213

1314
const actions = {
15+
'quick-edit': quickEdit,
1416
'set-as-homepage': setAsHomepage,
1517
'set-as-posts-page': setAsPostsPage,
1618
} satisfies Record< string, ActionScriptParts< any > >;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
/**
3+
* The "Quick edit" action, for pages, in the lists of the screens: it opens
4+
* the quick edit form of the pages the way the screen does. Its JavaScript
5+
* parts (`label`, `icon`, `isEligible`, and `callback`) are in `action.tsx`,
6+
* next to this file.
7+
*
8+
* @package WordPress
9+
*/
10+
11+
return array(
12+
'label' => __( 'Quick edit' ),
13+
'context' => 'list',
14+
'isPrimary' => true,
15+
'supportsBulk' => true,
16+
);
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { store as editorStore } from '@wordpress/editor';
2+
import { __ } from '@wordpress/i18n';
3+
import { drawerRight } from '@wordpress/icons';
4+
import { unlock } from '../../lock-unlock';
5+
import type { BasePost, ActionScriptParts } from '../../shared/types';
6+
7+
const quickEdit: ActionScriptParts< BasePost > = {
8+
label( items ) {
9+
return items.length > 1 ? __( 'Bulk edit' ) : __( 'Quick edit' );
10+
},
11+
icon: drawerRight,
12+
isEligible( post ) {
13+
return post.status !== 'trash';
14+
},
15+
callback( posts, { registry } ) {
16+
// The screen listing the pages sets how it opens their quick edit
17+
// form, see `setQuickEditOpener` in the editor store. Without it,
18+
// the action does nothing.
19+
const opener = unlock(
20+
registry.select( editorStore )
21+
).getQuickEditOpener();
22+
opener?.( {
23+
postType: posts[ 0 ].type,
24+
postIds: posts.map( ( post ) => post.id ),
25+
} );
26+
},
27+
};
28+
29+
/**
30+
* The JavaScript parts of the quick edit action of pages; its data is in
31+
* `action.php`. It opens the quick edit form with the opener of the screen,
32+
* so a screen showing the action must set one with `setQuickEditOpener`.
33+
*/
34+
export default quickEdit;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
/**
3+
* The "Edit" action, for pages, templates, template parts, patterns, and
4+
* navigation menus, in the lists of the screens: it opens the entity for
5+
* editing the way the screen does. Its JavaScript parts (`icon`,
6+
* `isEligible`, and `callback`) are in `action.tsx`, next to this file.
7+
*
8+
* @package WordPress
9+
*/
10+
11+
return array(
12+
'label' => _x( 'Edit', 'verb' ),
13+
'context' => 'list',
14+
);

0 commit comments

Comments
 (0)