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

Change edit links for templates and template parts #36294

Merged
merged 4 commits into from
Nov 8, 2021

Conversation

kevin940726
Copy link
Member

@kevin940726 kevin940726 commented Nov 8, 2021

Description

Close #35990.

Edit the "Edit" link of the items in Templates and Template Parts list to point to Site Editor.

How has this been tested?

  1. Enable block based theme like tt1-blocks
  2. Go to Appearance -> Templates and Appearance -> Template parts
  3. The item should have edit links pointing to the site editor urls

Types of changes

Bug fix

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).

@kevin940726 kevin940726 added the [Feature] Template Editing Mode Related to the template editor available in the Block Editor label Nov 8, 2021

$edit_link = 'themes.php?page=gutenberg-edit-site&postId=%1$s&postType=%2$s';

return admin_url( sprintf( $edit_link, urlencode( $template->id ), $template->type ) );
Copy link
Member

Choose a reason for hiding this comment

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

The core function uses admin_url as well instead of the path - https://developer.wordpress.org/reference/functions/get_edit_post_link/

Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Sorry for nitpicking, @kevin940726.

The feature works as expected.

Copy link
Contributor

@anton-vlasenko anton-vlasenko left a comment

Choose a reason for hiding this comment

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

I had some feedback, but it was resolved in 2165683.
Is there a possibility to add a unit test (or tests) for gutenberg_get_edit_template_link function?
I can add them if you wish so, @kevin940726.

@kevin940726
Copy link
Member Author

@anton-vlasenko It's yours now! ❤️

@jameskoster
Copy link
Contributor

jameskoster commented Nov 8, 2021

It's working well, but this change exposed another related issue.

When editing a template now, clicking the W button takes you back to the Dashboard. This is inconsistent with editing posts and pages, where clicking the W takes you to the relevant list view.

Should we address that here or in a follow-up?

@Mamaduka
Copy link
Member

Mamaduka commented Nov 8, 2021

@jameskoster, I think we should handle that in a separate PR. I can do a follow-up later today.

@jameskoster
Copy link
Contributor

I think we should handle that in a separate PR. I can do a follow-up later today.

Excellent. To clarify:

  • Clicking the W button while editing a template or template part should take you back to Appearance > Templates or Appearance > Tempalte parts respectively.
  • Clicking the W button in Appearance > Editor (beta) should probably continue to take you back to the Dashboard.

I mention this since the Editor (beta) link effectively takes you to the same place as editing a template.

return $link;
}

$edit_link = 'themes.php?page=gutenberg-edit-site&postId=%1$s&postType=%2$s';
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we use build_query to build $edit_link?
cc @Mamaduka

Copy link
Member

Choose a reason for hiding this comment

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

I think it's a simple enough query that there's no need to use build_query or add_query_arg.

P.S. In the future, this path can be a part of a post type of object via the _edit_link argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is a library function for building queries, and it feels like we are inventing the wheel here.
But I'm not going to insist we need to change it because we encode the request parameters (as it should be).

Copy link
Contributor

@anton-vlasenko anton-vlasenko left a comment

Choose a reason for hiding this comment

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

I've added a unit test.
LGTM now.

@Mamaduka
Copy link
Member

Mamaduka commented Nov 8, 2021

Thank you, @anton-vlasenko.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Template Editing Mode Related to the template editor available in the Block Editor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use template editing mode when editing a template via Appearance > Templates
6 participants