コード例 #1
0
ファイル: TabExtension.php プロジェクト: Maksold/platform
 /**
  * @param string $menuName
  * @param array  $options
  *
  * @throws \Symfony\Component\Validator\Exception\InvalidArgumentException
  * @return array
  */
 public function getTabs($menuName, $options = [])
 {
     /* @var MenuItem $menu */
     $menu = $this->menuExtension->getMenu($menuName, [], $options);
     $tabs = [];
     foreach ($menu->getChildren() as $child) {
         if (!$child->isDisplayed()) {
             continue;
         }
         if (!($url = $child->getUri())) {
             if ($route = $child->getExtra('widgetRoute')) {
                 $routeParameters = array_merge($child->getExtra('widgetRouteParameters', []), $options);
                 $routeParametersMap = $child->getExtra('widgetRouteParametersMap', []);
                 foreach ($routeParametersMap as $routeParameter => $optionParameter) {
                     if (isset($options[$optionParameter])) {
                         $routeParameters[$routeParameter] = $options[$optionParameter];
                         unset($routeParameters[$optionParameter]);
                     }
                 }
                 $url = $this->router->generate($route, $routeParameters);
             } else {
                 throw new InvalidArgumentException(sprintf('Extra parameter "widgetRoute" should be defined for %s', $child->getName()));
             }
         }
         if ($this->securityFacade->isGranted($child->getExtra('widgetAcl'))) {
             $label = $child->getLabel();
             if (!empty($label)) {
                 $label = $this->translator->trans($label);
             }
             $tabs[] = ['alias' => $child->getName(), 'label' => $label, 'widgetType' => $child->getExtra('widgetType', self::DEFAULT_WIDGET_TYPE), 'url' => $url];
         }
     }
     if (empty($tabs)) {
         $menu->setDisplay(false);
     }
     return $tabs;
 }
コード例 #2
0
 protected function assertRender($menu, $menuInstance, $options, $renderer)
 {
     $this->helper->expects($this->once())->method('render')->with($menuInstance, $options, $renderer)->will($this->returnValue('MENU'));
     $this->assertEquals('MENU', $this->menuExtension->render($menu, $options, $renderer));
 }
コード例 #3
0
 /**
  * {@inheritDoc}
  */
 public function getContent()
 {
     return $this->menuExtension->render($this->menu);
 }
コード例 #4
0
 public function testWrongBredcrumbs()
 {
     $environment = $this->getMockBuilder('\\Twig_Environment')->disableOriginalConstructor()->getMock();
     $this->breadcrumbManager->expects($this->once())->method('getBreadcrumbs')->will($this->returnValue(null));
     $this->assertNull($this->menuExtension->renderBreadCrumbs($environment, 'test_menu'));
 }