예제 #1
0
 public function setUri($uri)
 {
     if (is_array($uri)) {
         $uri = Router::url($uri);
     }
     return parent::setUri($uri);
 }
예제 #2
0
 public function testDeepGetIsCurrentAncestor()
 {
     $this->addChildWithExternalUrl();
     $this->menu->setCurrentUri('http://php.net');
     $this->gc1->setUri('http://php.net');
     $this->assertFalse($this->pt1->isCurrentAncestor());
     $this->assertTrue($this->menu->isCurrentAncestor());
     $this->assertTrue($this->pt2->isCurrentAncestor());
     $this->assertTrue($this->ch4->isCurrentAncestor());
 }
예제 #3
0
 public function get($name, array $options = array())
 {
     //get the internal pages of the website
     $menu = parent::get($name, $options);
     if ($name === 'simple') {
         //Home menu item
         $item = new MenuItem('Home', $this->factory);
         $item->setUri($menu->getUri());
         $menu->addChild($item);
         $item->moveToFirstPosition();
     }
     return $menu;
 }
예제 #4
0
 /**
  * Add items into the breadcrumb based on a given child.
  *
  * @param MenuItem $item
  * @param string   $locale
  */
 private function addItemsBasedOnTheChild(MenuItem $item, $locale)
 {
     if ($item !== null) {
         $items = array();
         $temporaryItem = $item;
         while ($temporaryItem->getParent() !== null) {
             $breadCrumb = new MenuItem($temporaryItem->getName(), $this->factory);
             $breadCrumb->setLabel($temporaryItem->getLabel());
             if ($temporaryItem->getUri() !== '#' && $temporaryItem->getUri() !== null) {
                 $breadCrumb->setUri($temporaryItem->getUri());
             }
             $items[] = $breadCrumb;
             $temporaryItem = $temporaryItem->getParent();
         }
         $home = new MenuItem('core.menu.home', $this->factory);
         $home->setLabel('core.menu.home');
         $home->setUri('/' . $locale);
         $this->items[] = $home;
         $this->items = array_merge($this->items, array_reverse($items));
     }
 }
예제 #5
0
 public function testIfItemIsAdded()
 {
     $this->createSimpleBreadCrumb();
     $requestStack = $this->getMockBuilder('\\Symfony\\Component\\HttpFoundation\\RequestStack')->getMock();
     $requestStack->method('getCurrentRequest')->willReturn($this->getMock('\\Symfony\\Component\\HttpFoundation\\Request'));
     $first = new MenuItem('first', $this->getFactory(null));
     $first->setUri('http://www.example.org');
     $this->breadCrumbBuilder->addItem($first);
     $last = new MenuItem('last', $this->getFactory(null));
     $this->breadCrumbBuilder->addItem($last);
     $this->breadCrumbBuilder->dontExtractFromTheRequest();
     $breadCrumb = $this->breadCrumbBuilder->createBreadCrumb($requestStack);
     $this->assertEquals(2, count($breadCrumb->getChildren()));
     $this->assertEquals('first', $breadCrumb->getChild('first')->getLabel());
     $this->assertEquals('http://www.example.org', $breadCrumb->getChild('first')->getUri());
     $this->assertEquals('last', $breadCrumb->getLastChild()->getLabel());
     $this->assertNull($breadCrumb->getLastChild()->getUri());
 }