Example #1
0
 /**
  * Recursively set attributes on an item and its' children
  *
  * @param Menu $menu
  * @param array $attr
  */
 public function setRecursiveAttribute(\Knp\Menu\MenuItem $menu, array $attr)
 {
     $itemIterator = new RecursiveItemIterator($menu->getIterator());
     $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $menuItem) {
         /** @var \Knp\Menu\MenuItem $menuItem */
         $menuItem->setChildrenAttributes($attr);
     }
 }
 /**
  * Recursively get parents
  *
  * @param $menu - menu to look for the parent in
  * @param $childNode - menu node whose parent we are looking for
  * @return mixed
  */
 public function getParentMenu(Menu $menu, MenuItem $childNode)
 {
     $itemIterator = new RecursiveItemIterator($menu->getIterator());
     $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
     foreach ($iterator as $menuItem) {
         $parentId = $childNode->getParent()->getId();
         if ($menuItem->getName() != $parentId) {
             continue;
         }
         return $menuItem;
     }
     return false;
 }