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: Add an API to retrieve content-only inner blocks #30674

Open
priethor opened this issue Apr 9, 2021 · 8 comments
Open

Navigation: Add an API to retrieve content-only inner blocks #30674

priethor opened this issue Apr 9, 2021 · 8 comments

Comments

@priethor
Copy link
Contributor

@priethor priethor commented Apr 9, 2021

What problem does this address?

As of 10.4-RC1, the Navigation block allows different kinds of inner blocks, from the most basic Navigation Link to the Search block, including layout-building ones like the Spacer block.

Because of this, obtaining a structured, link-only page hierarchy from a Navigation block (for example, to create a sitemap) is not as simple as gathering all inner blocks, as it would require discarding presentation-only blocks and other non-content ones.

What is your proposed solution?

The Navigation block should provide an API to retrieve content-only inner blocks.

@mtias
Copy link
Contributor

@mtias mtias commented Apr 12, 2021

This will be an important server side function to retrieve a data-relational representation since the navigation block can have other blocks in the mix that are not relevant.

@gwwar
Copy link
Contributor

@gwwar gwwar commented Apr 22, 2021

Do we have an example of what this API looks like and what it might return (eg either a rest call / php or JS function signature)? This would help me understand the usecase

@mtias
Copy link
Contributor

@mtias mtias commented Apr 22, 2021

I had in mind something similar to the nav menu walker but taking advantage of the built in object tree representation of nested blocks to be used in server-side context (could be exposed in REST as well), excluding any presentation specific elements.

@priethor
Copy link
Contributor Author

@priethor priethor commented Apr 22, 2021

Regarding what constitutes the content to be returned by this API, I'm thinking of linking blocks in any flavor (Navigation link, Social links, Home link, Site Title/Logo...), but not other functional blocks like Search, even if it is not a presentation-specific element. Does that make sense, @mtias?

@priethor priethor added this to To do in Navigation block via automation Apr 23, 2021
@draganescu
Copy link
Contributor

@draganescu draganescu commented Jun 3, 2021

Are there two parts to this task?

  1. Add some function that gets a header template part and gets the navigation blocks in that template part
  2. Add an API in the Navigation block that can create a tree data representation of all the blocks that act as links

Without (1) how would we know where to find the blocks?

@priethor
Copy link
Contributor Author

@priethor priethor commented Jun 3, 2021

I don't think we need (1) at the moment, as the Navigation block can be placed in other template parts or posts. I can see designs having a Navigation block in their Header and Footer template parts, or different headers with different navigations, and nothing prevents them from having more than one Navigation block instance per template part.

Starting with (2) would allow wrapping items properly when rendering the frontend as suggested in #31951 (comment). Furthermore, it could also help render responsive menus by outputting different HTML for smaller screens excluding the non-content blocks.

@draganescu
Copy link
Contributor

@draganescu draganescu commented Jun 7, 2021

I think I described (1) incorrectly. I meant from any generic template part a function that would get the name of the template part and the name of the block that we're looking for and gets that block back. I don't think we have such a thing.

@talldan
Copy link
Contributor

@talldan talldan commented Sep 1, 2021

Starting with (2) would allow wrapping items properly when rendering the frontend as suggested in #31951 (comment). Furthermore, it could also help render responsive menus by outputting different HTML for smaller screens excluding the non-content blocks.

I'm not sure using this for rendering is the right track, because it's shifting away from the block rendering paradigm (which should itself be able to support this use case).

Perhaps this could be something that's not so much navigation block specific, but instead works on the basis of the HTML markup. That would ensure third-party blocks aren't left out of the mix.

It could build a hierarchy of the links inside a <nav> element. Any such utility could still work on the basis of a specific navigation block if needed, it'd just use the rendered output.

The other thought I have if this path isn't considered viable is that this could take advantage of the experimentalRole property on attributes to try to apply some semantic meaning to attributes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants