public function createItem($itemArray) { if (is_array($itemArray)) { if (array_key_exists('text', $itemArray) && array_key_exists('url', $itemArray)) { $navItem = new sfNavBuilderItem(); $navItem->setDisplayName($itemArray['text'])->setUrl(url_for($itemArray['url'])); if (array_key_exists('class', $itemArray)) { $navItem->setClass($itemArray['class']); } if (array_key_exists('activate_when', $itemArray)) { $navItem->addActivateWhen($itemArray['activate_when']); } if (array_key_exists('credentials', $itemArray)) { $navItem->addCredentialRules($itemArray['credentials']); } if (array_key_exists('childrens', $itemArray)) { foreach ($itemArray['childrens'] as $childArray) { $childMenu = $this->createItem($childArray); if ($childMenu) { $navItem->addChild($childMenu); } } } return $navItem; } } }
/** * Sets this item as the parent of the supplied item allowing hierarchy to * be created in the menu * @param sfNavBuilderItem $i An item to set as the parent of this item * @return sfNavBuilderItem $this The current sfNavBuilderItem instance * @see addChild() for alternative hierarchy creation */ public function setParent(sfNavBuilderItem $i) { $i->addChild($this); return $this; }
/** * Works out if the menu item is active * @param sfNavBuilderItem $item The item to check * @return Boolean $ret */ public function isItemActive(sfNavBuilderItem $item) { $ret = FALSE; // look at the activation criteria and see if they are met foreach ($item->getActivateWhen() as $activate) { // minimum for activation is an array of modules to check if (in_array($this->_context->module, $activate['module'])) { // check actions if defined if (isset($activate['action'])) { if (in_array($this->_context->action, $activate['action'])) { // check params if defined if (isset($activate['paramName']) && isset($activate['paramVal'])) { if (in_array($this->_request->getParameter($activate['paramName']), $activate['paramVal'])) { $ret = TRUE; break; } } else { $ret = TRUE; break; } } } else { $ret = TRUE; break; } } } return $ret; }