ZF-10458: Ability to register custom navigation helpers outside of Zend Library to interact with proxy found in navigation

Description

When Attempting to create a custom navigation view helper I found if difficult to register it with the navigation view helper.

i.e. App_View_Helper_Navigation_Context should be accessible through $this->navigation->context()

In order to provide this functionality I had to subclass the navigation helper but as its quite a straight forward improvement I have included a patch for Zend_View_Helper_Navigation


--- library/Zend/View/Helper/Navigation.php (revision 22945)
+++ library/Zend/View/Helper/Navigation.php (working copy)
@@ -156,10 +156,13 @@
             return $this->_helpers[$proxy];
         }
 
-        if (!$this->view->getPluginLoader('helper')->getPaths(self::NS)) {
-            $this->view->addHelperPath(
-                    str_replace('_', '/', self::NS),
-                    self::NS);
+        $paths = $this->view->getPluginLoader('helper')->getPaths();
+        foreach($paths AS $ns => $path) {
+            if (!$this->view->getPluginLoader('helper')->getPaths($ns . 'Navigation_')) {
+                $this->view->addHelperPath(
+                        str_replace('_', '/', $ns . 'Navigation_'),
+                        $ns . 'Navigation');
+            }
         }
 
         if ($strict) {

Comments

Patch file for mentioned change

Hi Matt, I see no problem!

Add your path for the helper and the prefix for the class to {{Zend_View}}.

Set view helper path:


or

And you can use your own navigation helper by proxy: ```

My unit test for this issue runs without any failures.

I found a problem:

A helper with the name "My_View_Helper_Navigation_Menu" can not be used, because the proxy helper returns always the standard view helper "Zend_View_Helper_Navigation_Menu".

Patch and unit tests added.

tests fail:


$ phpunit34 Zend/View/Helper/Navigation/AllTests.php 
PHPUnit 3.4.15 by Sebastian Bergmann.

............................................................  60 / 165
............................................................ 120 / 165
.......................PHP Fatal error:  Call to undefined method Zend_View_Helper_Navigation_NavigationTest::assertInstanceOf() in /www/zend-framework/zf1/standard-trunk/tests/Zend/View/Helper/Navigation/NavigationTest.php on line 393

Fatal error: Call to undefined method Zend_View_Helper_Navigation_NavigationTest::assertInstanceOf() in /www/zend-framework/zf1/standard-trunk/tests/Zend/View/Helper/Navigation/NavigationTest.php on line 393

Updated unit tests.

Resolved in svn r24986(trunk) and r24987(release-1.12)

Hi Rob,

The fix doesn't seems to work on 1.12.0 as far as I see.

Basically I don't need to add another view helper path right? Or should I add:

resources.view.helperPath.My_View_Helper_Navigation = "My/View/Helper/Navigation"

?

@[~avantis]

You must add the helper path! Look at the unit tests for examples.

The problem was: {quote}A helper with the name "My_View_Helper_Navigation_Menu" can not be used, because the proxy helper returns always the standard view helper "Zend_View_Helper_Navigation_Menu".{quote}

If you have more questions please write me an e-mail.