From 5b395f05c8e17b19d0be58ba155c2df5c256cefe Mon Sep 17 00:00:00 2001 From: George Mamadashvili Date: Wed, 8 Jan 2025 14:05:27 +0400 Subject: [PATCH] Try: New default rendering mode for editor via post type supports --- ...tenberg-rest-post-types-controller-6-8.php | 61 ------------------- lib/compat/wordpress-6.8/post.php | 60 ------------------ lib/compat/wordpress-6.8/rest-api.php | 15 ----- lib/load.php | 2 - .../editor/src/components/provider/index.js | 24 +++++--- 5 files changed, 16 insertions(+), 146 deletions(-) delete mode 100644 lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php delete mode 100644 lib/compat/wordpress-6.8/post.php diff --git a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php b/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php deleted file mode 100644 index da0489210e21f1..00000000000000 --- a/lib/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php +++ /dev/null @@ -1,61 +0,0 @@ -default_rendering_mode, $item ); - - /** - * Filters the block editor rendering mode for a specific post type. - * Applied after the generic `post_type_default_rendering_mode` filter. - * - * The dynamic portion of the hook name, `$item->name`, refers to the post type slug. - * - * @since 6.8.0 - * @param string $default_rendering_mode Default rendering mode for the post type. - * @param WP_Post_Type $post_type Post type object. - * @return string Default rendering mode for the post type. - */ - $rendering_mode = apply_filters( "post_type_{$item->name}_default_rendering_mode", $rendering_mode, $item ); - - // Validate the filtered rendering mode. - if ( ! in_array( $rendering_mode, gutenberg_post_type_rendering_modes(), true ) ) { - $rendering_mode = 'post-only'; - } - - $response->data['default_rendering_mode'] = $rendering_mode; - } - - return rest_ensure_response( $response ); - } -} diff --git a/lib/compat/wordpress-6.8/post.php b/lib/compat/wordpress-6.8/post.php deleted file mode 100644 index be842d89b51519..00000000000000 --- a/lib/compat/wordpress-6.8/post.php +++ /dev/null @@ -1,60 +0,0 @@ -register_routes(); - } -} -add_action( 'rest_api_init', 'gutenberg_add_post_type_rendering_mode' ); - // When querying terms for a given taxonomy in the REST API, respect the default // query arguments set for that taxonomy upon registration. function gutenberg_respect_taxonomy_default_args_in_rest_api( $args ) { diff --git a/lib/load.php b/lib/load.php index 371f9c54e5fc4a..b145d44376280f 100644 --- a/lib/load.php +++ b/lib/load.php @@ -44,7 +44,6 @@ function gutenberg_is_experiment_enabled( $name ) { // WordPress 6.8 compat. require __DIR__ . '/compat/wordpress-6.8/block-comments.php'; require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-comment-controller-6-8.php'; - require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-post-types-controller-6-8.php'; require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-hierarchical-sort.php'; require __DIR__ . '/compat/wordpress-6.8/rest-api.php'; @@ -98,7 +97,6 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/compat/wordpress-6.8/preload.php'; require __DIR__ . '/compat/wordpress-6.8/blocks.php'; require __DIR__ . '/compat/wordpress-6.8/functions.php'; -require __DIR__ . '/compat/wordpress-6.8/post.php'; require __DIR__ . '/compat/wordpress-6.8/site-editor.php'; require __DIR__ . '/compat/wordpress-6.8/class-gutenberg-rest-user-controller.php'; diff --git a/packages/editor/src/components/provider/index.js b/packages/editor/src/components/provider/index.js index 133a52e2ce01bc..59767aba750a32 100644 --- a/packages/editor/src/components/provider/index.js +++ b/packages/editor/src/components/provider/index.js @@ -180,15 +180,23 @@ export const ExperimentalEditorProvider = withRegistryProvider( getRenderingMode, __unstableIsEditorReady, } = select( editorStore ); - const { getEntitiesConfig } = select( coreStore ); + const { + getEntitiesConfig, + getPostType, + hasFinishedResolution, + } = select( coreStore ); - const postTypeObject = select( coreStore ).getPostType( - post.type + const postTypeSupports = getPostType( post.type )?.supports; + const _hasLoadedPostObject = hasFinishedResolution( + 'getPostType', + [ post.type ] ); - const _hasLoadedPostObject = select( - coreStore - ).hasFinishedResolution( 'getPostType', [ post.type ] ); + const _defaultMode = Array.isArray( postTypeSupports?.editor ) + ? postTypeSupports.editor.find( + ( features ) => 'default_mode' in features + )?.default_mode + : undefined; return { hasLoadedPostObject: _hasLoadedPostObject, @@ -196,8 +204,8 @@ export const ExperimentalEditorProvider = withRegistryProvider( isReady: __unstableIsEditorReady(), mode: getRenderingMode(), defaultMode: - hasTemplate && postTypeObject?.default_rendering_mode - ? postTypeObject?.default_rendering_mode + hasTemplate && _defaultMode + ? _defaultMode : 'post-only', selection: getEditorSelection(), postTypeEntities: