PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_Menu » Bug #2815

_findNodeType fails with forced URL

Details

Submitted2004-11-23 18:35 UTC
Frominfo at e-novative dot de
StatusNo Feedback
PackageHTML_Menu
PHP Version5.0.2
OSWindows XP
Roadmaps(Not assigned)

Comments

[2004-11-23 18:35 UTC] info at e-novative dot de

Description:
------------
_findNodeType always uses the current URL instead of the forced URL. I think line 284:

if ($this->_currentUrl == $nodeUrl) {

should read

if ($this->getCurrentURL() == $nodeUrl) {

[2004-11-26 14:19 UTC] info at e-novative dot de

I have code that proves what I am claiming, without calling private methods. The following class will create a menu where "highlighting" the current page _does_ work (we are using fully dynamic page generation, so we can't use the default method(s)). If you comment out the _findNodeType() method in this class, the "highlighting" of the current page does not work:

<?php

/**
* @package cms
*/

/**
* Enable class autoloading.
*/
require_once 'autoload.php';

/**
* CMS Menu
*
* CMS Menu
*
* @package cms
* @subpackage gui
*/
class CmsMenu extends HTML_Menu
{
protected $Tree = array();

public function __construct()
{
parent::HTML_Menu();
}

function setTree($aTree)
{
$this->Tree = $aTree;
}

function display()
{
$this->setMenu($this->Tree);
$this->forceCurrentUrl(Cms::$Page);

$renderer = new HTML_Menu_DirectRenderer();
$renderer->setEntryTemplate(HTML_MENU_ENTRY_INACTIVE, '<td>{indent}<a href="{url}" class="{class}" onClick="{onclick}" title="{tooltip}">{title}</a></td>');
$this->render($renderer, 'sitemap');

return $renderer->toHtml();
}

/**
* Modified from HTML_Menu: uses fakeurl instead of url
*/
function _renderTree($menu, $level = 0)
{
foreach ($menu as $node_id => $node) {
$type = $this->_findNodeType($node_id, $node['fakeurl'], $level);

$this->_renderer->renderEntry($node, $level, $type);
$this->_renderer->finishRow($level);

// follow the subtree if the active menu item is in it or if we want the full menu
if (('sitemap' == $this->_menuType || HTML_MENU_ENTRY_INACTIVE != $type) && isset($node['sub'])) {
$this->_renderTree($node['sub'], $level + 1);
}
}
$this->_renderer->finishLevel($level);
if (0 == $level) {
$this->_renderer->finishMenu($level);
}
}

/**
* Modified from HTML_Menu: fixed getCurrentURL bug.
*/
function _findNodeType($nodeId, &$nodeUrl, $level)
{
$nodeUrl = $this->_urlPrefix . ((empty($this->_urlPrefix) || '/' != $nodeUrl{0})? $nodeUrl: substr($nodeUrl, 1));

if ($this->getCurrentURL() == $nodeUrl) {
// menu item that fits to this url - 'active' menu item
return HTML_MENU_ENTRY_ACTIVE;
} elseif (isset($this->_path[$level]) && $this->_path[$level] == $nodeId) {
// processed menu item is part of the path to the active menu item
return 'urhere' == $this->_menuType? HTML_MENU_ENTRY_BREADCRUMB: HTML_MENU_ENTRY_ACTIVEPATH;
} else {
// not selected, not a part of the path to the active menu item
return HTML_MENU_ENTRY_INACTIVE;
}
}
}

?>