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

Navigation Block: Add support for a dynamic home URL #20542

Closed
kjellr opened this issue Feb 28, 2020 · 16 comments · Fixed by #30926
Closed

Navigation Block: Add support for a dynamic home URL #20542

kjellr opened this issue Feb 28, 2020 · 16 comments · Fixed by #30926
Assignees
Labels
[Block] Navigation Affects the Navigation Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Task Issues or PRs that have been broken down into an individual action to take

Comments

@kjellr
Copy link
Contributor

kjellr commented Feb 28, 2020

Today, when you add a homepage menu item in the Navigation Block, this gets mapped directly to that page's ID & URL. For example:

<!-- wp:navigation -->
<!-- wp:navigation-link {"label":"Home","id":1837,"url":"https://wordpress.test/?page_id=1837"} /-->
<!-- /wp:navigation -->

This is fine for a single site, but when the navigation block is used in a theme template or template part (or even in a block pattern), we'll want a way to have a homepage link dynamically map directly to the site's homepage, via something like home_url().

@kjellr kjellr added [Type] Enhancement A suggestion for improvement. [Block] Navigation Affects the Navigation Block labels Feb 28, 2020
@mtias mtias added the [Type] Task Issues or PRs that have been broken down into an individual action to take label Feb 29, 2020
@mtias
Copy link
Member

mtias commented Feb 29, 2020

Absolutely. This is also related to the tasks of removing the url attribute for site resources.

@scruffian scruffian modified the milestone: 5.6 Nov 19, 2020
@scruffian scruffian added the [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. label Nov 19, 2020
@bobbingwide
Copy link
Contributor

I took a pragmatic approach to this problem in bobbingwide/fizzie#22
I intercept the navigation link block, adjust the attributes, then call the original rendering function.

In my theme I've left the hardcoded string as originally coded.
eg

function fizzie_render_block_core_navigation_link( $attributes, $content, $block ) {
    $attributes = fizzie_nav_atts( $attributes );
    $html = gutenberg_render_block_core_navigation_link($attributes, $content, $block);
    return $html;
}

function fizzie_nav_atts( $attributes ) {
    $attributes['url'] = str_replace( 'https://s.b/wp56', site_url(), $attributes['url'] );
    return $attributes;
}

@mtias
Copy link
Member

mtias commented Nov 27, 2020

I think we should create a special block variation of Link that is Home, showing up as such in the inserter.

@priethor priethor self-assigned this Jan 5, 2021
@gwwar
Copy link
Contributor

gwwar commented Feb 10, 2021

@priethor were you still working on this one?

@priethor
Copy link
Contributor

I kind of am. I expect to retake it in a few days as it's a good first issue but can of course pass it along as soon as it starts becoming a blocker. 👍

@gwwar
Copy link
Contributor

gwwar commented Feb 10, 2021

Sounds good @priethor 👍 Let us know if anything changes.

@mtias
Copy link
Member

mtias commented Mar 15, 2021

Where are we with this one?

@priethor
Copy link
Contributor

I was exploring this last week, and my first impression is that a block variation might not be the best solution, as the block would better be a dynamic one so that the link stays in sync with the home URL whenever it's changed in the settings. Also, it would require a different workflow and state handling than normal links as it would never be empty and would not require placeholder states, for example.

In any case, as the need for this feature becomes more prominent, I think it's about time for me to unassign the issue and let somebody focus on it and truly bring it forward.

@priethor priethor removed their assignment Mar 15, 2021
@gwwar
Copy link
Contributor

gwwar commented Mar 15, 2021

As an FYI these two landed, so another navigation link variation + some custom handling should do the trick.
#29095
WordPress/wordpress-develop#1015

Folks should also be aware of the following issue in the navigation editor:
#29793

@priethor
Copy link
Contributor

Thanks @gwwar , those changes simplify the Home variation, indeed! 💯

@mtias
Copy link
Member

mtias commented Mar 15, 2021

Curious why this one needs to be a variation instead of just its own block as a wrapper for get_home_url?

@gwwar
Copy link
Contributor

gwwar commented Mar 15, 2021

Curious why this one needs to be a variation instead of just its own block as a wrapper for get_home_url?

It's own block would work too.

@mtias
Copy link
Member

mtias commented Mar 15, 2021

I'd say a separate block makes more sense since we don't need any of the UI to set a custom link.

@priethor
Copy link
Contributor

we don't need any of the UI to set a custom link

I started exploring the block variation based on previous comments on the issue, but because of not needing any of the UI, I find a separate block would keep it simpler and wouldn't violate the open-closed principle.

@gwwar
Copy link
Contributor

gwwar commented Apr 13, 2021

@priethor was there a PR here to help review?

@priethor
Copy link
Contributor

There isn't, I explored the variation but didn't proceed with the new block @gwwar. It's open to being picked among the Navigation block priorities.

@gwwar gwwar self-assigned this Apr 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation Affects the Navigation Block [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Status] In Progress Tracking issues with work in progress [Type] Enhancement A suggestion for improvement. [Type] Task Issues or PRs that have been broken down into an individual action to take
Projects
None yet
6 participants