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 [Feature] Themes [Status] In Progress [Type] Enhancement [Type] Task

Comments

@kjellr
Copy link
Contributor

@kjellr 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().

@mtias
Copy link
Member

@mtias mtias commented Feb 29, 2020

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

@scruffian scruffian added this to the 5.6 milestone Nov 19, 2020
@scruffian scruffian removed this from the 5.6 milestone Nov 19, 2020
@scruffian scruffian added the [Feature] Themes label Nov 19, 2020
@bobbingwide
Copy link
Contributor

@bobbingwide bobbingwide commented Nov 25, 2020

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 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 gwwar commented Feb 10, 2021

@priethor were you still working on this one?

@priethor
Copy link
Contributor

@priethor priethor commented Feb 10, 2021

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 gwwar commented Feb 10, 2021

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

@mtias
Copy link
Member

@mtias mtias commented Mar 15, 2021

Where are we with this one?

@priethor
Copy link
Contributor

@priethor priethor commented Mar 15, 2021

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 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

@priethor priethor commented Mar 15, 2021

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

@mtias
Copy link
Member

@mtias 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 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 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

@priethor priethor commented Mar 15, 2021

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 gwwar commented Apr 13, 2021

@priethor was there a PR here to help review?

@priethor
Copy link
Contributor

@priethor priethor commented Apr 14, 2021

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
@github-actions github-actions bot added the [Status] In Progress label Apr 16, 2021
@priethor priethor added this to 📥 To do in WordPress 5.8 Must Haves via automation Apr 20, 2021
@priethor priethor added this to To do in Navigation block via automation Apr 23, 2021
@priethor priethor moved this from To do to In progress in Navigation block Apr 23, 2021
@priethor priethor moved this from 📥 To do to 🏗️ In progress in WordPress 5.8 Must Haves Apr 23, 2021
WordPress 5.8 Must Haves automation moved this from 🏗️ In progress to ✅ Done May 10, 2021
Navigation block automation moved this from 🏗️ In progress to ✅ Done May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Navigation [Feature] Themes [Status] In Progress [Type] Enhancement [Type] Task
Projects
6 participants