-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Set editor rendering mode by post type #62304
Feature: Set editor rendering mode by post type #62304
Conversation
…deringMode value into the Editor rendering function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you work on this @TylerB24890 🚀
This is working exactly as I hoped it would. :) I left some minor notes and will request some additional reviews :)
lib/compat/wordpress-6.6/class-gutenberg-rest-post-types-controller-6-6.php
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking very good to me. I'd appreciate broader review as well. @jameskoster @jasmussen @mcsf
…perty to read default_rendering_mode.
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is working great for me for what it's worth. Nice addition.
I also checked what would happen if I logged in as an Author with template-locked
enabled - it activates the "Show template" option 👍🏻
Just left a comment about value checking, though even if it's a valid remark, I don't think it should block the first version of this.
Nice PR. Took it for a quick spin. In a very superficial test—this could use broader opinions—this seems to work as intended. If I change the default post-editor rendering mode to show templates, it does: Otherwise it still shows the current default: I think of these defaults as valid user settings to set as well at some point, user settings that are reasonable to persist, so if we add this, it would be good that a future user-setting could also unset whatever a plugin or theme might do. I.e. if my theme sets my page editor to omit the template preview, but I really prefer editing with that, I should be able to override that in my user settings. Make sense? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Thanks all for your help here. This is a nice one. |
🎉 This is great! This is exactly what we need for the email editor project. We always want to display full email content including template content. |
if ( | ||
wp_is_block_theme() && | ||
( isset( $args['show_in_rest'] ) && $args['show_in_rest'] ) && | ||
( isset( $args['supports'] ) && in_array( 'editor', $args['supports'], true ) ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is causing a crash when the supports
arg to register_post_type
is false
:
Fatal error: Uncaught TypeError: in_array(): Argument #2 ($haystack) must be of type array, bool given in /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.8/post.php:42
Stack trace:
#0 /var/www/html/wp-content/plugins/gutenberg/lib/compat/wordpress-6.8/post.php(42): in_array('editor', false, true)
#1 /var/www/html/wp-includes/class-wp-hook.php(324): gutenberg_post_type_default_rendering_mode(Array, 'product_variati...')
#2 /var/www/html/wp-includes/plugin.php(205): WP_Hook->apply_filters(Array, Array)
#3 /var/www/html/wp-includes/class-wp-post-type.php(491): apply_filters('register_post_t...', Array, 'product_variati...')
#4 /var/www/html/wp-includes/class-wp-post-type.php(467): WP_Post_Type->set_props(Array)
#5 /var/www/html/wp-includes/post.php(1805): WP_Post_Type->__construct('product_variati...', Array)
#6 /var/www/html/wp-content/plugins/woocommerce/includes/class-wc-post-types.php(442): register_post_type('product_variati...', Array)
WooCommerce registers its product_variation
post type with supports => false
. It's a supported and documented value for supports
, whose type is array|false
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixing in #67225.
The setting was added in WordPress/gutenberg#62304 and is needed with the newest Gutenberg version. [MAILPOET-6319]
The setting was added in WordPress/gutenberg#62304 and is needed with the newest Gutenberg version. [MAILPOET-6319]
The setting was added in WordPress/gutenberg#62304 and is needed with the newest Gutenberg version. [MAILPOET-6319]
It's been a few weeks, and I still find the new default rendering mode confusing for pages. Maybe the pages should default to IMO, this is a significant behavior change for Pages in the post editor. Unfortunately, we'll only get real feedback after WP 6.8 is released. Update: The change also breaks page editing for non-Administrator users with P.S. There's already a report about the changes in List View behavior for page - #67857. Screenshot (broken page for Editors) |
@Mamaduka I'll say that I have shipped 3 projects where we used the hacky JS approach to change the default rendering mode: import { registerPlugin } from '@wordpress/plugins';
import { useDispatch, useSelect } from '@wordpress/data';
import { useEffect } from '@wordpress/element';
import { store as editorStore } from '@wordpress/editor';
// Define post types that show the full template locked site editor by default.
const TEMPLATE_LOCKED_POST_TYPES = ['page', 'post'];
registerPlugin('namespace-set-default-template-rendering-mode', {
render: function Edit() {
const { setRenderingMode } = useDispatch(editorStore);
const [postType] = useSelect((select) => [select(editorStore).getCurrentPostType()], []);
useEffect(() => {
if (!TEMPLATE_LOCKED_POST_TYPES.includes(postType)) {
return;
}
setRenderingMode('template-locked');
}, [setRenderingMode, postType]);
return null;
},
}); And have had great success with it. However when we changed it, we changed it across the board for all content types so the behavior was consistent. I agree that it is a big change and we should definitely be careful about rolling it out. I hope that if we decide to roll it back though, that we keep the underlying property on the CPT so that we can override the default rendering mode much easier than we do it today since the solution today creates some unstyled flashes of content whilst loading |
Do you have any more details about:
This here only changes the default? It was long before possible to preview the template even as a non admin. Sounds like there is a regression there 🤔 |
Can we please rename default_rendering_mode to something else that makes it clearer that it‘s about the editor? Maybe prefix it with editor_ at least. Also, have you considered using the post type supports feature for that, rather than adding a new top level prperty? |
@swissspidy all open on the name 👍
Yes but deemed it not the right choice here because even before this was merged in a block theme every single post type supports the ability to preview the template as you are editing the post. So this is not a new support, it is just enabling it by default. (Allowing you to change the default) Since there are multiple possible options here we would need a key value pair of some kind 🤔 which post type supports are not |
@fabiankaegy, I'm not saying we should revert the whole feature; I quite like it. I think we should consider whether Pages will ship with
I don't have them now, but when the default rendering mode is set to
That would require changing the shape of the |
So? :) That sounds feasible to implement and has come up in the past already anyway. It could be added as a config to the editor support. Definitely worth exploring IMO. Way more future proof if you need any more configs in the future.
If post type support doesn‘t work, I‘d suggest editor_rendering_mode at least. |
Maybe we should fold editor-specific settings into a new object. Technically speaking, |
One thing that I personally value is the consistency between site and post editors, these are not separate editors, these are just how things have evolved and it will "merge" fully at some point (single url). That said for the choice of the default rendering mode for pages, I think it's a very hard question to answer, I've seen feedback in both ways: some folks (mostly devs) have a clear separation in their head so they prefer just the abstracted view, some users prefer to see the full page. |
I take it back, this actually is supported!
|
@swissspidy, can you clarify? Does that mean that the post type
@youknowriad, I think we should ship this as an opt-in feature, at least for now. |
The problem for me is the inconsistency with the site editor, we need to change one behavior, so it's going to change something regardless. |
@Mamaduka Yes! Example: |
$rendering_mode = $args['default_rendering_mode']; | ||
} | ||
|
||
$args['default_rendering_mode'] = $rendering_mode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Surprised that we even allow adding custom args... We should have added an allowlist.
@youknowriad, how should we handle users who can edit pages but not templates and template parts? Currently, page editing is broken for these users. |
@fabiankaegy, I'll debug it tomorrow. It could be an unrelated issue; I also see the We also need to test various cases to ensure everything works as expected. Here's a bug report for the case we missed, #67875. Some flows that come to mind:
|
What?
Related Issue & PR:
block_editor_settings_all
hook in PHP to allow customizing it #61844Track Ticket: https://core.trac.wordpress.org/ticket/61811
Backport PR: WordPress/wordpress-develop#7129
This PR adds a filterable
default_rendering_mode
property to theWP_Post_Type
object allowing users to define the default rendering mode for the editor for that post type.The
default_rendering_mode
property can be added to the arguments when registering the post type viaregister_post_type()
and can be overwritten using the available filters:post_type_{$post_type}_default_rendering_mode
: To target an individual specific post type.post_type_default_rendering_mode
: To target all (or multiple) post types.Why?
Currently there is no way to set the default rendering mode of the block editor. You can select the mode while in the block editor, but upon refreshing that mode is reset back to the default
post-only
. With this update developers have more control over the editing experience and provides a means of setting the default view for the block editor.How?
The linked PR has a discussion that mentions this setting should be applied at the post type level, allowing for a difference editing mode per post type. This PR applies the
default_rendering_mode
property to theWP_Post_Type
object itself and provides multiple ways of overriding or setting the default for a custom (or core) post type.Testing Instructions
post
post type and observe the default editor UI.functions.php
file (or similar) use one of the available filters to set thedefault_rendering_mode
property totemplate-lock
:post
editor and confirm you are now seeing the Template UI instead of the default Post UI.page
post and confirm thepage
editor also loads with the Template UI.functions.php
to target only thepage
post type:page
editor and confirm it still renders the Template UI.post
editor and confirm it now renders the default Post UI.functions.php
to set the rendering mode for thepost
andpage
post types, but no others:register_post_type
and set thedefault_rendering_mode
parameter totemplate-lock
:post-only
and refresh the Site Editor.