Skip to content
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

Let Gutenberg be default editor for posts with blocks; add links to classic editor #1797

Merged
merged 11 commits into from
Sep 8, 2017

Conversation

westonruter
Copy link
Member

@westonruter westonruter commented Jul 7, 2017

Fixes #1779, #1627.

When a post contains blocks, the main edit link becomes the link to Gutenberg whereas the row action link then goes to the Classic Editor:

image

Any edit post link for a post with blocks becomes a link to the Gutenberg editor, including links on the frontend:

image

If a post does not contain blocks, then the main link remains pointing to the classic editor and the Gutenberg link is in the row actions.

Likewise, if a post does have blocks then when the post is viewed on the frontend, the “Edit Post” link will link to Gutenberg and it will have a “Edit in Gutenberg” title. The classic editor will then be available via a submenu item:

image

Likewise, when the post does not contain blocks, then the original Edit Post link is in place with a link to Gutenberg being in the submenu as the alternate edit mode:

image

Lastly, if the post type is not registered with show_in_rest then the Gutenberg editor is not shown, since the REST API is a dependency for Gutenberg.

@westonruter
Copy link
Member Author

I'll add unit tests for the new PHP functions once a 👍 on the functionality is given.

@afercia
Copy link
Contributor

afercia commented Jul 9, 2017

While there's the need to keep the links text as short as possible, given the limited space, I'd consider to try to improve them a bit.

  • all the row actions use verbs: Edit, Quick Edit, View, Preview, etc.: "Classic Editor" and "Gutenberg" instead don't immediately communicate the available action
  • the action of the "Edit" link in the list table and the "Edit Post" in the toolbar can be inferred only looking at the link close to them, not sure if this will be immediately clear for users

screen shot 2017-07-09 at 13 52 15
screen shot 2017-07-09 at 13 54 44
screen shot 2017-07-09 at 13 52 40
screen shot 2017-07-09 at 13 52 49

screen shot 2017-07-09 at 13 50 52
screen shot 2017-07-09 at 13 51 13

Since the aria-label text is not visible, it could be expanded always specifying "in the classic editor" / "in the Gutenberg editor"

@westonruter
Copy link
Member Author

the action of the "Edit" link in the list table and the "Edit Post" in the toolbar can be inferred only looking at the link close to them, not sure if this will be immediately clear for users

@afercia I'm not entirely clear if your feedback here is about the design of the WordPress post list table in general, or if it is specifically regarding changes in this PR.

@afercia
Copy link
Contributor

afercia commented Jul 10, 2017

@westonruter I meant the current list table design in WordPress is clear enough because there's just one "Edit" and just one editor. Now that this PR introduces 2 links to 2 different editors, it's not always immediately clear where the "Edit" link points.

@westonruter
Copy link
Member Author

It links to the default editor. If you think it should be verbosely “Edit in Gutenberg”, I wouldn't be opposed, but again there is limited space.

@afercia
Copy link
Contributor

afercia commented Jul 10, 2017

Yep that's what I meant 🙂 I see the limited space issue. Shortening the link text is not always so clear though.

@westonruter
Copy link
Member Author

Please amend the PR with whatever you deem best.

@westonruter westonruter added the [Status] In Progress Tracking issues with work in progress label Jul 11, 2017
lib/register.php Outdated
*/
function gutenberg_post_has_blocks( $post_id ) {
$post = get_post( $post_id );
return $post && preg_match( '#<!-- wp:\w+#', $post->post_content );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about strpos( $post->post_content, '<!-- wp:' ) !== false?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably would be just as good in the vast majority of cases. That sequence of chars shouldn't be present unless there are blocks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that if <!-- wp: is already there, the chance is very high that it is followed by a word-like sequence anyway.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the input. Changed in 53e2def.

@westonruter
Copy link
Member Author

Rebased. 326645d rewritten to ef5a661.

@mtias mtias added Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Priority] High Used to indicate top priority items that need quick attention labels Aug 2, 2017
@karmatosed
Copy link
Member

+1 to getting this merged from me. Can we get a refresh to pass all checks? Be great to get this in for 1.1.

@afercia
Copy link
Contributor

afercia commented Aug 30, 2017

@karmatosed I kindly disagree. There's still a design issue to solve here: the link destination is not always clear.

@karmatosed
Copy link
Member

@afercia to me, we get the PR in a state we can then see (it's not yet) and then either merge and iterate or iterate. What are you thinking is missing and would advise?

@afercia
Copy link
Contributor

afercia commented Aug 31, 2017

@karmatosed for example: would you be able to understand what the two "Edit" links in the screenshot below do at first sight?

screen shot 2017-08-31 at 09 03 49

To me, this seems confusing because I can understand the difference between the two "Edit" only by looking at the other link close to them. Not to mention, the link on the post title doesn't say anything either.

I see potential confusion also in the toolbar: often times, users just click, they don't read (muscle memory also). They will see "Edit bla bla" and click and sometimes land in the classic editor, sometimes on Gutenberg.

@aduth
Copy link
Member

aduth commented Sep 1, 2017

To me, it seems like it might be good to have edit actions as "Gutenberg Editor" (or "Edit in Gutenberg"), "Classic Editor" (or "Edit in Classic Editor") in all cases (never changing order or text), then set the behavior of the title link to the preferred default (Gutenberg if blocks exist, Classic otherwise).

@aduth
Copy link
Member

aduth commented Sep 1, 2017

I've rebased to resolve conflicts and made the following revisions:

Using the display_post_states filter, add a "Gutenberg" status in post table for posts containing blocks:

Gutenberg status

Always show "Classic Editor" and "Gutenberg" links in post actions, regardless of post contents:

Post actions

Always show full "Edit in ..." text in front-end admin bar:

Admin bar

lib/register.php Outdated
$gutenberg_action = sprintf(
if ( gutenberg_post_has_blocks( $post->ID ) ) {
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 );
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@westonruter Should we just add a default filter handler for get_edit_post_link to always override with the preferred editor by content?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what is already done here?

gutenberg/lib/register.php

Lines 210 to 231 in 547d038

/**
* Filters the post edit link to default to the Gutenberg editor when the post content contains a block.
*
* @since 0.5.0
*
* @param string $url The edit link URL.
* @param int $post_id Post ID.
* @param string $context The link context. If set to 'display' then ampersands are encoded.
* @return string Edit post link.
*/
function gutenberg_filter_edit_post_link( $url, $post_id, $context ) {
$post = get_post( $post_id );
if ( gutenberg_can_edit_post( $post_id ) && gutenberg_post_has_blocks( $post_id ) && post_type_supports( get_post_type( $post_id ), 'editor' ) ) {
$gutenberg_url = gutenberg_get_edit_post_url( $post->ID );
if ( 'display' === $context ) {
$gutenberg_url = esc_url( $gutenberg_url );
}
$url = $gutenberg_url;
}
return $url;
}
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why the remove_filter and add_filter are done above is to facilitate obtaining the classic post editor URL, even for a post that has blocks in it:

$classic_text = __( 'Edit in Classic Editor', 'gutenberg' );
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 );
$classic_url = get_edit_post_link( $post->ID, 'raw' );
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, seeing that now in the changes prior to 63ff18d. I guess this might not be working correctly for the "Classic Editor" link for Gutenberg posts currently then.

lib/register.php Outdated
$gutenberg_action = sprintf(
if ( gutenberg_post_has_blocks( $post->ID ) ) {
remove_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10 );
add_filter( 'get_edit_post_link', 'gutenberg_filter_edit_post_link', 10, 3 );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it stands right now, this if condition with add/remove of the get_edit_post_link filter is just removing and adding something right back, so it has no purpose right?

@aduth
Copy link
Member

aduth commented Sep 6, 2017

54df7bc should resolve the issue where Classic Editor would use an incorrect link for Gutenberg posts (from discussion thread at #1797 (comment)).

From my perspective, this seems ready to go.

@codecov
Copy link

codecov bot commented Sep 6, 2017

Codecov Report

Merging #1797 into master will increase coverage by 1%.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #1797    +/-   ##
========================================
+ Coverage   31.38%   32.39%    +1%     
========================================
  Files         177      182     +5     
  Lines        5413     5933   +520     
  Branches      949     1087   +138     
========================================
+ Hits         1699     1922   +223     
- Misses       3139     3348   +209     
- Partials      575      663    +88
Impacted Files Coverage Δ
blocks/editable/index.js 10.02% <0%> (-0.5%) ⬇️
editor/sidebar/post-status/index.js 0% <0%> (ø) ⬆️
blocks/library/gallery/gallery-image.js 50% <0%> (ø) ⬆️
blocks/editable/constants.js 100% <0%> (ø)
editor/sidebar/post-pending-status/index.js 58.33% <0%> (ø)
components/autocomplete/index.js 89.04% <0%> (ø)
blocks/block-autocomplete/index.js 100% <0%> (ø)
blocks/library/gallery/block.js 11.76% <0%> (ø)
blocks/editable/format-toolbar/index.js 8% <0%> (+0.5%) ⬆️
components/drop-zone/provider.js 1.98% <0%> (+0.64%) ⬆️
... and 10 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8621e54...54df7bc. Read the comment docs.

@aduth aduth merged commit b9bdfa2 into master Sep 8, 2017
@aduth aduth deleted the add/edit-post-links branch September 8, 2017 17:36
aaronjorbin added a commit that referenced this pull request Sep 9, 2017
`get_edit_post_link` is used in `post.php` to redirect when saving. See https://core.trac.wordpress.org/browser/trunk/src/wp-admin/post.php#L190

By checking to see if the referer is the classic editor, modification to the edit post link is preserved.

Introduced in #1797
Fixes #2707
aduth pushed a commit that referenced this pull request Sep 27, 2017
`get_edit_post_link` is used in `post.php` to redirect when saving. See https://core.trac.wordpress.org/browser/trunk/src/wp-admin/post.php#L190

By checking to see if the referer is the classic editor, modification to the edit post link is preserved.

Introduced in #1797
Fixes #2707
Tug pushed a commit that referenced this pull request Feb 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Priority] High Used to indicate top priority items that need quick attention [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants