Skip to content

Instantly share code, notes, and snippets.

@twogood
Created November 9, 2012 11:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save twogood/4045344 to your computer and use it in GitHub Desktop.
Save twogood/4045344 to your computer and use it in GitHub Desktop.
Customizing Zend\View\Helper\Navigation\Menu
<?php
namespace Application\View\Helper\Navigation;
use Zend\View\Helper\Navigation\Menu;
class CustomMenu extends Menu
{
// override methods as needed
}
<?php
namespace Application\View\Helper\Navigation;
use Zend\ServiceManager\ConfigInterface;
use Zend\View\Helper\Navigation\PluginManager;
class CustomPluginManager extends PluginManager
{
public function __construct(ConfigInterface $configuration = null)
{
parent::__construct($configuration);
$this->invokableClasses[$this->canonicalizeName('menu')]
= 'Application\View\Helper\Navigation\CustomMenu';
}
}
<?php
echo $this
->navigation('Navigation')
->setPluginManager(new \Application\View\Helper\Navigation\CustomPluginManager())
->menu();
?>
@SmasherHell
Copy link

that solution work but I can't accept to construct new object in views for testing matters.

After some research, I found that Navigation Helper is not shared, or it is the twig module that mess up sharing, and if I try to add custom plugin to Navigation (such as a new menu) in module bootstrap, it is just ineffective. But I found an interesting thing in reading Navigation Helper construction in

Zend\Navigation\View\HelperConfig.php

the Navigation plugin manager can be configured in module, global or local config under the key navigation_helpers. That is an easy way to extends Navigation with plugins.

Ex :

module.config.php

'navigation_helpers' => array (
    'invokables' => array(
        'menu' => 'Application\View\Helper\Navigation\Menu',
    ),
),

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