Issues

ZF-11876: Zend_View_Helper_Navigation_Menu does not render custom Page properties

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:


$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

Code tags added.

{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:


$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/…

{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!

Patch and unit tests added.

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


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

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

Thanks for your work!

My result:


Zend_Navigation_PageTest "/trunk/tests/Zend/Navigation/PageTest.php"

OK (73 tests, 134 assertions)

Process finished with exit code 0

(?)

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:


$ phpunit34 Zend/Navigation/PageTest.php

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


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

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

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

Fixed in trunk (1.12.0): r24879

Thanks, Frank!