Issues

ZF-11876: Zend_View_Helper_Navigation_Menu does not render custom Page properties

Issue Type: Bug Created: 2011-11-09T11:31:31.000+0000 Last Updated: 2012-06-06T13:09:43.000+0000 Status: Resolved Fix version(s): - 1.12.0 (27/Aug/12)

Reporter: Przemys?aw Wróbel (wrobel) Assignee: Frank Brückner (frosch) Tags: - Zend_Navigation

  • FixForZF1.12
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-9300

Attachments: - Navigation.helper.patch

Description

Zend_View_Helper_Navigation_Menu does render Page _properties as html attributes in htmlify() method. It allows only to use id, title, target, href and class like below:

<pre class="highlight">
$attribs['href']   = $href;
$attribs['target'] = $page->getTarget();

$attribs = array(
    'id'     => $page->getId(),
    'title'  => $title,
    'class'  => $page->getClass()
);

What if one wants to add "onclick" atribute for example. The only way now is to use JavaScript (perhaps it is a better solution in such case) but generally one should be able to add custom attributes. I think there should be an array_merge with Page's $_properties array?

Comments

Posted by Frank Brückner (frosch) on 2011-11-09T11:42:30.000+0000

Code tags added.

Posted by Frank Brückner (frosch) on 2011-11-09T12:00:26.000+0000

{quote}I think there should be an array_merge with Page's $_properties array?{quote} Bad idea, because not all custom page properties are also allowed HTML attributes! Look at the first example in docs:

<pre class="highlight">
$page = new Zend_Navigation_Page_Mvc();
$page->foo = 'bar';
$page->meaning = 42;
 
echo $page->foo;
 
if ($page->meaning != 42) {
    // action should be taken
}

http://framework.zend.com/manual/en/…

Posted by Frank Brückner (frosch) on 2011-11-09T22:33:30.000+0000

{quote}The only way now is to use JavaScript (perhaps it is a better solution in such case){quote} This is the best solution. We are in 2011 and inline event handlers are from the last millennium. :-) Use Unobtrusive JavaScript!

Posted by Frank Brückner (frosch) on 2012-03-22T18:56:00.000+0000

Patch and unit tests added.

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-31T23:33:36.000+0000

Frank: When I applied your patches and ran the Navigation tests I got one failure:

<pre class="highlight">
1) Zend_Navigation_PageTest::testToArrayMethod
Failed asserting that two arrays are equal.
--- Expected
+++ Actual
@@ @@
 Array
 (
+    [customHtmlAttribs] => Array
+        (
+        )
+
 )

Posted by Frank Brückner (frosch) on 2012-06-01T06:25:59.000+0000

Hi Adam, I will check this and create a new patch.

Thanks for your work!

Posted by Frank Brückner (frosch) on 2012-06-01T12:15:02.000+0000

My result:

<pre class="highlight">
Zend_Navigation_PageTest "/trunk/tests/Zend/Navigation/PageTest.php"

OK (73 tests, 134 assertions)

Process finished with exit code 0

(?)

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-05T13:10:00.000+0000

Intriguing....Could you try applying your patches to a clean SVN trunk? When I do that, I only count 68 tests in Zend_Navigation_PageTest and I get the failure I included in my previous comment:

<pre class="highlight">
$ phpunit34 Zend/Navigation/PageTest.php

1) Zend_Navigation_PageTest::testToArrayMethod
Failed asserting that two arrays are equal.


FAILURES!
Tests: 68, Assertions: 128, Failures: 1.

Posted by Frank Brückner (frosch) on 2012-06-05T13:23:25.000+0000

Sh*t! I have forgotten one patch. Sorry, my mistake.

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-06T13:05:16.000+0000

Aha! That would do it. Everything passes now :)

Posted by Adam Lundrigan (adamlundrigan) on 2012-06-06T13:09:42.000+0000

Fixed in trunk (1.12.0): r24879

Thanks, Frank!

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