core icon indicating copy to clipboard operation
core copied to clipboard

make navigation extendable

Open Toflar opened this issue 13 years ago • 22 comments

Hi Leo

One thing that I really find annoying in Contao is that the navigation module is limited to the tl_page table and there's no way to hook upon.

Some scenarios:

  • The catalog provides the possibility to generate a navigation out of a catalog but I can't tell the catalog to add its generated navigation *into Home->Products so it in fact generates a submenu of "Products"
  • Isotope could have the same use case as the catalog
  • I wrote a customer specific module where the editors can describe sports. Every sport has to have its own navigation point and the two subpages "Description" and "Rules". The whole thing should be generated automatically. No problem at all except for adding the sports navigation to Home->Association->Sports.
  • I could imagine that this could be very interesting when writing a front end admin panel for any software. Let's say you want to integrate any API from a third party application and provide the functionalities of this application within the default Contao navigation module. Same problem here...

I don't think that a hook in the current navigation module is the way to go because that would end up in too many useless hook calls (and you'd need to run through every registered hook for every page). I rather think of a new library called "Navigation" that controls a navigation array (that can be extended - that's the point) and all the ModuleNavigation has to do would be

$this->Template->items = Navigation::generate($trail[$level]);

The fact that there exist several extensions (found "xNavigation" and "backboneit_navigation", maybe there are others) that try to solve this issue (but with hooks...) should also be evidence of the need to extend the navigation of Contao.

What do you think? ;)

--- Originally created on June 14th, 2011, at 10:06am (ID 3162)

Toflar avatar Nov 29 '11 21:11 Toflar

Related to that point, some times ago I integrated member groups und members as items into the navi. It was a hard work.

--- Originally created on June 14th, 2011, at 08:37pm

Aybee avatar Nov 29 '11 21:11 Aybee

I'd like to provide some Features in a Mega-Menu Navigation (f.e. a Login directly un the Suckerfish-Dropdown) so I'd like to see that as soon as possible ;-) Hope you'll accept this ticket.

--- Originally created on June 15th, 2011, at 03:45pm

HellPat avatar Nov 29 '11 21:11 HellPat

Can you post a patch file please?

--- Originally created on June 23rd, 2011, at 01:43pm

leofeyer avatar Nov 29 '11 21:11 leofeyer

That's going to be a huge one ;) Will see what I can do for you =)

--- Originally created on June 24th, 2011, at 08:18am

Toflar avatar Nov 29 '11 21:11 Toflar

I will publish the functionality as an extension in the extension repository. I'm going to copy the core navigation module so other developers can use it and the core doesn't get affected. This way we can collect feedback, improve the Navigation class and eventually see whether we want to integrate it into the core or not. Guess that's the best approach. I've got the basic functionality ready but it will need some more fine tuning, optimization and testing. I'm going to inform the devs when the extension is published and the docs are ready =)

--- Originally created on June 25th, 2011, at 10:58am

Toflar avatar Nov 29 '11 21:11 Toflar

I really dislike the idea of duplicating a feature in the Repo. Why not implement it in 2.11?

--- Originally created on June 27th, 2011, at 09:31am

aschempp avatar Nov 29 '11 21:11 aschempp

I have created a project on GitHub: https://github.com/Toflar/extnavigation In addition to this I have started a thread in the German developer forum but still I welcome anybody to work on it!!

--- Originally created on June 30th, 2011, at 03:57pm

Toflar avatar Nov 29 '11 21:11 Toflar

Take a look at my extension "backboneit_navigation" it features all requests: ER: http://www.contao.org/erweiterungsliste/view/backboneit_navigation.10000009.de.html (german) Wiki: http://de.contaowiki.org/Backboneit_navigation (german)

Additionally it is faster than the core navigation (1 query per level instead of 1 query per parent page, and without correlated subqueries), has more features (multiple root pages, flexible start/stop/hard limit which also applies on custom root pages, use current page as root page, etc.) and is cleaner in the calculation (eg. subtrees under protected paths are not rendered).

--- Originally created by backbone on July 6th, 2011, at 03:13pm

ghost avatar Nov 29 '11 21:11 ghost

Looks quite good and if it really is faster and needs less queries, I think we should really consider taking this into the core. Let's see what Leo has to add =)

--- Originally created on July 6th, 2011, at 03:31pm

Toflar avatar Nov 29 '11 21:11 Toflar

For small navigations the overhead for the additional calculations on the root pages (protected or not) could result in a slower performance, because the path must be checked. But here again only 1 query per level is needed, eg. 10 custom root pages where the deepest node is in level 3 and hard limit is on 3 (relative to the roots), requires at most 7 queries (1 for root level, 3 upwards, 3 downwards). Additionally each internal redirect is resolved separatly and recursivly, which could result in very much queries, but this feature could be removed or chopped or the internal redirect aliases could be stored together with the internal redirect page while editing tl_page datasets.

If the module is picked up for the core, please let me know before you integrate it, because then I'd like to revise the API before it got in.

--- Originally created by backbone on July 6th, 2011, at 03:42pm

ghost avatar Nov 29 '11 21:11 ghost

Together with Toflar, I revised the hooking and pretty much made it as comfortable as possible. Also a lot of fixes for some corner configurations. Basically you can now add "Virtual Pages" which hooks in pages from the Newssystem, Catalog or Anywhere.

--- Originally created by backbone on July 11th, 2011, at 05:20pm

ghost avatar Nov 29 '11 21:11 ghost

Has been revised again and Oliver published version 1.1

![](I strongly recommend taking a look at it and probably get in touch with him. I used it to extend the navigation with the hook he provides which is now pretty easy to do) It's faster, start and stop level seem to be easier to understand, extendable, cleaner in calculation, provides even more features than the core navigation already does -> in other words, could well make it into the core!

--- Originally created on July 14th, 2011, at 10:55am

Toflar avatar Nov 29 '11 21:11 Toflar

It looks like you have some error because you referencing this ticket in an unrelated commit

backbone87 avatar Dec 09 '11 16:12 backbone87

Came here because of the recent blog post. Checked the issue and I still think our navigation module should be improved.

Toflar avatar Nov 26 '15 10:11 Toflar

Let's discuss this in our next call.

leofeyer avatar Dec 23 '15 15:12 leofeyer

As discussed in Mumble on January 26th, @backbone87 is going to start a PR with a new navigation module for Contao 4.

leofeyer avatar Jan 26 '17 14:01 leofeyer

This ticket appears to have stalled. Can it be closed or do you want to start/keep working on it?

leofeyer avatar Mar 20 '18 12:03 leofeyer

Same as ever: I still think it would make sense to improve the module but we should probably go for knp menu here, too. Maybe something for @sheeep or @backbone87 :)

Toflar avatar Mar 20 '18 12:03 Toflar

It would be great if there will be more options for navigation. We already have an extended navigation module for Contao https://github.com/backbone87/contao-navigation ... I think there are some things which could be implemented ... @backbone87 should think about it!

frontendschlampe avatar Mar 20 '18 12:03 frontendschlampe

i agree with @Toflar -> we should somehow facilitate knp menu, since we already use it in the BE. the question is how we handle twig templates in the FE?

the codebase for my navigation is stable but somewhat dated. so a little bit of polishing isnt enough imho.

backbone87 avatar Apr 24 '18 08:04 backbone87

Contao 4 uses the KnpMenuBundle now, so I guess this ticket can be closed.

leofeyer avatar Dec 09 '21 16:12 leofeyer

Contao 4 uses the KnpMenuBundle now, so I guess this ticket can be closed.

Only for the back end, not for the front end. This would still be a cool feature to have for the front end navigation module.

fritzmg avatar Dec 09 '21 16:12 fritzmg