Issues

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

Issue Type: Improvement Created: 2010-09-15T05:59:23.000+0000 Last Updated: 2012-09-03T07:36:17.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Matt Cockayne (matt.cockayne) Assignee: Frank Brückner (frosch) Tags: - Zend_Navigation

  • FixForZF1.12.1
  • state:patch-ready-for-review
  • zf-crteam-padraic
  • zf-crteam-priority

Related issues: Attachments: - Navigation.php.patch

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

<pre class="highlight">
--- 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

Posted by Matt Cockayne (matt.cockayne) on 2010-09-15T06:00:40.000+0000

Patch file for mentioned change

Posted by Frank Brückner (frosch) on 2011-11-05T20:56:32.000+0000

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:

<pre class="highlight">
or

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

My unit test for this issue runs without any failures.

Posted by Frank Brückner (frosch) on 2011-11-15T21:57:21.000+0000

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".

Posted by Frank Brückner (frosch) on 2011-11-15T21:59:47.000+0000

Patch and unit tests added.

Posted by Rob Allen (rob) on 2012-06-19T19:00:38.000+0000

tests fail:

<pre class="highlight">
$ 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

Posted by Frank Brückner (frosch) on 2012-06-19T19:59:50.000+0000

Updated unit tests.

Posted by Rob Allen (rob) on 2012-06-19T20:30:55.000+0000

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

Posted by Cristian Bichis (avantis) on 2012-08-31T16:37:49.000+0000

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"

?

Posted by Frank Brückner (frosch) on 2012-09-03T07:36:17.000+0000

@[~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.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts