-
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
base: trunk
Are you sure you want to change the base?
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.
packages/editor/src/components/provider/use-block-editor-settings.js
Outdated
Show resolved
Hide resolved
I'm also still very confused what is happening with the mobile unit tests 🤔 |
For the mobile unit tests, what's happening is that |
This comment was marked as outdated.
This comment was marked as outdated.
This has been fixed in a742e4a |
@youknowriad this appears to be a legitimate bug in the mobile editor, not an issue in the unit test setup. The gutenberg/packages/editor/src/components/provider/index.js Lines 327 to 330 in a742e4a
I observed that, in the mobile editor, the |
@dcalhoun As you can see here, we have this code in the editor provider
This code performs a REST API to fetch the post type with the rendering mode. I don't know how to test the app personally but at least in the mobile unit tests, that object was always "undefined" which means, nothing was rendered. |
@youknowriad correct, but if that object is gutenberg/packages/editor/src/components/provider/index.js Lines 197 to 198 in a742e4a
I will continue debugging, but wanted to ask if you had insight on that oddity. |
In case it helps, There's this condition
This condition means that we don't render anything if the object didn't load yet, regardless of whether there's a fallback rendering mode. |
Recent changes in the editor provider enable setting the rendering mode via post type. The changes result conditionally rendering the visual editor until the mode is determined. Without the required reducers, the mobile editor never updated the rendering mode state, thus never rendering the visual editor.
The mobile editor only supports the `post-only` rendering mode, so we presume a resolved `getPostType` selector to unblock editor rendering. This is necessary as the editor provider awaits post type resolution before rendering the entirety of the editor.
@youknowriad @TylerB24890 the mobile editor breakage and failing automated tests should be resolved by the following:
The former is merged, the latter needs review and merging. 🚀 |
This comment was marked as outdated.
This comment was marked as outdated.
@youknowriad in my digging it appears that this line here when we load the sample HTML file for the large post
That doesn't update the blocks that are stored in the post content but rather replaces the blocks in the template itself 🤔 I have added a workarround that switches the rendering mode to |
…e whenever we load in the large post html file
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.