Menupoly does provide an API to load and render menus and submenus very similar to those you get with Menu Block, based on a configuration array.
Menus can be rendered in a block or standalone (e.g. directly in page.tpl.php).
hook_menupoly(). (See the example module)
Standalone: Create the $settings array in code, then call
$settings = array( 'expand' => MENUPOLY_EXPAND_ALL, 'menu_name' => 'user-menu', ... // more options possible ); $html = menupoly_view($settings);
Crumbs support: Submenus don't collapse on deep browsing.
Full support for Crumbs, specifically
crumbs_get_trail(), to determine which submenus should be expanded, and which items should get an "active" or "active-trail" class.
- You navigate to Home > News, and see the respective submenu being expanded.
- You visit one of the news, "Two-headed squirrel found dead".
- With core or menu_block:
- The menu collapses, because the news node is not in the menu.
- Also, the breadcrumb is back to Home > Squirrel found dead.
- After installing Crumbs and doing a bit of config:
- Breadcrumb is at Home > News > Squirrel found dead.
- Menu is still collapsed.
- Using Menupoly for the menus (and Crumbs):
- Menu is expanded to Home > News, and the active trail is highlighted.
- With core or menu_block:
Rendering plugins, instead of theme()
With traditional Drupal, you would override theme('menu_link') etc on the theme layer, to make your menus look different. This often requires nasty if/else/switch logic in these theme functions, to check which instance of a menu you are on.
Menupoly does support these theming functions, but it provides an alternative that allows to set a rendering plugin (object implementing menupoly_MenuTheme), which allows to have your modifications all in one place. E.g. you could write one plugin for your flat top navigation, another for a dropdown top navigation, another for a sidebar menu block, and yet another for a footer sitemap. These rendering plugins can live in a custom module or in your theme.
$settings = array( 'menu_name' => 'menu-topnav', // limited to first level 'depth' => 1, 'menu_theme' => new mymodule_MenuTheme_TopnavFlat(), );
Language suffix on menu names
Menupoly can automatically choose one of several menus based on the current language matching a suffix in the menu name.
If you have separate menus per language, suffixed as my-menu, my-menu-fr, my-menu-de, my-menu-he etc, then menupoly can automatically pick the correct language version for you.
$settings = array( 'menu_name' => 'menu-topnav', // Automatically switch to menu-topnav-fr, menu-topnav-it, etc, based on current language 'i18n_menu_name_suffix' => TRUE, );
Code over configuration
Menupoly follows the philosophy that it's better to write a bit of code on a clean API, instead of clicking around in an admin UI. Code can be easily copied, migrated, version controlled. If you want to do that with configuration you need things like features, and as nice as this may be, it is not as transparent as some simple code.
Menupoly menus can act as blocks. But in many cases it is better to hardcode the menu into the theme's page.tpl.php and template.php. This way you totally circumvent the admin GUI, and also avoid unnecessary html.
A useful guideline can be: Menus in the header (user menu, top nav dropdown) can be hardcoded into your theme, whereas sidebar menus work better as blocks.
Menupoly has its own dedicated algorithms for loading menu trees or partial menu trees. When the module was intially written, this promised to be a lot faster than the menu tree loading in D6 core.
Drupal 7 did catch up, so it is no longer certain whether menupoly does outperform core menu loading. Anyway, it should be fast enough.
(caching, mostly equivalent to what you get with core, is on the way and will land soon)
Dependencies: xautoload, htmltag
Menupoly uses X Autoload, to keep all its OOP code nicely organized. Menupoly uses the PHP 5.2 compatibility option of xautoload, so you don't have to upgrade your PHP (although it's probably a good idea to do it anyway).
The same pattern can be used for your custom MenuTheme plugins, e.g. in your custom theme. But if you wish, you can also go directly to PSR-0 namespaced classes.
Another dependency is HTML tag, which makes it easier to play with html attribute arrays. (don't worry about the alpha status, the module is good enough to be used with Menupoly)
- Maintenance status: Actively maintained
- Development status: Under active development
- Reported installs: 86 sites currently report using this module. View usage statistics.
- Downloads: 2,978
- Last modified: 2 December 2014
- Stable releases for this project are covered by the security advisory policy.
Look for the shield icon below.