/** * Modify menu by adding, removing or editing items. * * @param \Knp\Menu\ItemInterface $menu * @param array $options * @param string|null $alias */ public function build(ItemInterface $menu, array $options = array(), $alias = null) { $options['orderBy'] = array(array('field' => NavigationHistoryItem::NAVIGATION_HISTORY_COLUMN_VISIT_COUNT)); $maxItems = $this->configOptions->get('oro_navigation.maxItems'); if (!is_null($maxItems)) { $options['maxItems'] = $maxItems; } parent::build($menu, $options, $alias); }
public function testBuild() { $type = 'favorite'; $userId = 1; $user = $this->getMockBuilder('stdClass')->setMethods(array('getId'))->getMock(); $user->expects($this->once($userId))->method('getId')->will($this->returnValue(1)); $token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'); $token->expects($this->once())->method('getUser')->will($this->returnValue($user)); $this->securityContext->expects($this->once())->method('getToken')->will($this->returnValue($token)); $item = $this->getMock('Oro\\Bundle\\NavigationBundle\\Entity\\NavigationItemInterface'); $this->factory->expects($this->once())->method('createItem')->with($type, array())->will($this->returnValue($item)); $repository = $this->getMockBuilder('Oro\\Bundle\\NavigationBundle\\Entity\\Repository\\NavigationItemRepository')->disableOriginalConstructor()->getMock(); $items = array(array('id' => 1, 'title' => 'test1', 'url' => '/', 'type' => $type), array('id' => 2, 'title' => 'test2', 'url' => '/home', 'type' => $type)); $repository->expects($this->once())->method('getNavigationItems')->with($userId, $type)->will($this->returnValue($items)); $this->em->expects($this->once())->method('getRepository')->with(get_class($item))->will($this->returnValue($repository)); $menu = $this->getMockBuilder('Knp\\Menu\\ItemInterface')->getMock(); $menu->expects($this->exactly(2))->method('addChild'); $menu->expects($this->once())->method('setExtra')->with('type', $type); $this->builder->build($menu, array(), $type); }
/** * Modify menu by adding, removing or editing items. * * @param \Knp\Menu\ItemInterface $menu * @param array $options * @param string|null $alias */ public function build(ItemInterface $menu, array $options = array(), $alias = null) { $maxItems = $this->configOptions->get('oro_navigation.maxItems'); if (!is_null($maxItems)) { // we'll hide current item, so always select +1 item $options['maxItems'] = $maxItems + 1; } parent::build($menu, $options, $alias); $children = $menu->getChildren(); foreach ($children as $child) { if ($this->matcher->isCurrent($child)) { $menu->removeChild($child); break; } } $this->getMenuManipulator()->slice($menu, 0, $maxItems); }