/**
  * Set active class to current item and all its parents (so it is automatically opened)
  * 
  * @param ItemInterface $item
  */
 protected function setActive(ItemInterface $item = null)
 {
     if ($item) {
         $this->setActive($item->getParent());
         $item->setAttribute('class', $item->getAttribute('class', '') . ' active');
     }
 }
Пример #2
0
 /**
  * Create the dropdown menu.
  *
  * @param ItemInterface $rootItem
  * @param string        $title
  * @param array         $attributes
  * @param string        $caret
  *
  * @return \Knp\Menu\ItemInterface
  */
 public function createDropdownMenuItem(ItemInterface $rootItem, $title, $attributes = [], $caret = true)
 {
     // Add child to dropdown, still normal KnpMenu usage
     $options = array_merge(['dropdown' => true, 'childrenAttributes' => ['class' => 'vic-dropdown-menu'], 'attributes' => ['class' => 'vic-dropdown', 'data-toggle' => 'vic-dropdown'], 'linkAttributes' => ['class' => 'vic-dropdown-toggle', 'data-toggle' => 'vic-dropdown'], 'uri' => '#'], $attributes);
     $menu = $rootItem->addChild($title, $options)->setExtra('caret', $caret);
     return $menu;
 }
Пример #3
0
 /**
  * @param MenuItemInterface $menu
  * @param $action
  * @param AdminInterface $childAdmin
  */
 protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     $pool = $this->container->get('sonata.admin.pool');
     $adminGroups = $pool->getAdminGroups();
     foreach ($adminGroups as $name => $adminGroup) {
         if (isset($adminGroup['items'])) {
             foreach ($adminGroup['items'] as $key => $id) {
                 $admin = $pool->getInstance($id);
                 if ($admin->showIn(Admin::CONTEXT_DASHBOARD)) {
                     $groups[$name]['items'][$key] = $admin;
                 } else {
                     unset($groups[$name]['items'][$key]);
                 }
             }
         }
         if (empty($groups[$name]['items'])) {
             unset($groups[$name]);
         }
     }
     $menu->addChild($this->trans('dashboard', [], 'admin'), array('uri' => $this->getRouteGenerator()->generate('sonata_admin_dashboard'), 'attributes' => array('class' => 'home')));
     foreach ($groups as $name => $group) {
         $parent = $menu->addChild('header_' . $this->trans($name), array('label' => $this->trans($name), 'attributes' => array('class' => 'submenu')));
         foreach ($group['items'] as $key => $admin) {
             $item = $parent->addChild($this->trans($admin->getLabel()), array('uri' => $admin->generateUrl('list')));
             if (get_class($this) == get_class($admin)) {
                 $parent[$this->trans($admin->getLabel())]->setCurrent(true);
                 //$item['header_'.$this->trans($name)]->setAttributes(array('class' => 'submenu open'));
             }
         }
     }
 }
 protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!in_array($action, array('edit', 'create'))) {
         return;
     }
     $id = $this->getRequest()->get('id');
     $vars = $menu->addChild('Variables', array('route' => 'tsk_contract_default_variables', 'attr' => array('onclick' => 'alert("foo"); return false;')));
     $contract = $vars->addChild('Contract');
     $contract->addChild('getAmount');
     $contract->addChild('getProgram');
     $contract->addChild('getExpireDate');
     $contract->addChild('getRolloverTokens');
     $contract->addChild('getContractNumTokens');
     $contract->addChild('getProgramLegalDescription');
     $student = $vars->addChild('Student');
     $student->addChild('getContact.getFirstName');
     $student->addChild('getContact.getLastName');
     $student->addChild('getContact.getAddress1');
     $student->addChild('getContact.getAddress2');
     $student->addChild('getContact.getCity');
     $student->addChild('getContact.getState');
     $student->addChild('getContact.getPostalcode');
     $student->addChild('getContact.getPhone');
     $school = $vars->addChild('School');
     $school->addChild('getContact.getState');
     $org = $vars->addChild('Org');
     $org->addChild('getName');
 }
Пример #5
0
 /**
  * @param ItemInterface $item
  *
  * @return bool|null
  */
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->getRequest()) {
         return null;
     }
     $route = $this->getRequest()->attributes->get('_route');
     $routeParameters = $this->getRequest()->attributes->get('_route_params');
     if (null === $route) {
         return null;
     }
     $routes = (array) $item->getExtra('routes', array());
     foreach ($routes as $testedRoute) {
         if ($route == $testedRoute['route']) {
             if (is_array($routeParameters) && 0 < count($routeParameters)) {
                 if (isset($testedRoute['parameters']) && is_array($testedRoute['parameters'])) {
                     $matching = true;
                     foreach ($routeParameters as $index => $value) {
                         if ('_' != substr($index, 0, 1)) {
                             if (!isset($testedRoute['parameters'][$index]) || ($testedRoute['parameters'][$index] != $value && 0 < $testedRoute['parameters'][$index] || !is_numeric($value))) {
                                 $matching = false;
                             }
                         }
                     }
                     if ($matching) {
                         return true;
                     }
                 }
             } else {
                 return true;
             }
         }
     }
     return null;
 }
 /**
  * {@inheritDoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->getRequestUri()) {
         return true;
     }
     return null;
 }
Пример #7
0
 private function addChildNodes(ItemInterface $menu, MenuItem $menuItem)
 {
     $child = $menu->addChild($menuItem->getName(), $this->createMenuOptions($menuItem));
     foreach ($menuItem->getChildren() as $childItem) {
         $this->addChildNodes($child, $childItem);
     }
 }
Пример #8
0
 /**
  * @param ItemInterface $menu
  */
 private function addConfigurationMenu(ItemInterface $menu)
 {
     $child = $menu->addChild('configuration')->setLabel('sylius.menu.admin.main.configuration.header');
     if (!$child->hasChildren()) {
         $menu->removeChild('configuration');
     }
 }
 /**
  * @throws InvalidConfigurationException
  */
 public function configureTabMenu(AdminInterface $admin, MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!($subject = $admin->getSubject())) {
         return;
     }
     if (!$subject instanceof RouteReferrersReadInterface && !$subject instanceof Route) {
         throw new InvalidConfigurationException(sprintf('%s can only be used on subjects which implement Symfony\\Cmf\\Component\\Routing\\RouteReferrersReadInterface or Symfony\\Component\\Routing\\Route.', __CLASS__));
     }
     if ($subject instanceof PrefixInterface && !is_string($subject->getId())) {
         // we have an unpersisted dynamic route
         return;
     }
     $defaults = array();
     if ($subject instanceof TranslatableInterface) {
         if ($locale = $subject->getLocale()) {
             $defaults['_locale'] = $locale;
         }
     }
     try {
         $uri = $this->router->generate($subject, $defaults);
     } catch (RoutingExceptionInterface $e) {
         // we have no valid route
         return;
     }
     $menu->addChild($this->translator->trans('admin.menu_frontend_link_caption', array(), 'CmfRoutingBundle'), array('uri' => $uri, 'attributes' => array('class' => 'sonata-admin-menu-item', 'role' => 'menuitem'), 'linkAttributes' => array('class' => 'sonata-admin-frontend-link', 'role' => 'button', 'target' => '_blank', 'title' => $this->translator->trans('admin.menu_frontend_link_title', array(), 'CmfRoutingBundle'))));
 }
Пример #10
0
 /**
  * {@inheritdoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if (($page = $this->getPage()) && $page->getId() !== null) {
         return $item->getExtra('_page_id', null) === $page->getId();
     }
     return;
 }
Пример #11
0
 /**
  * Checks whether an item is current.
  *
  * If the voter is not able to determine a result,
  * it should return null to let other voters do the job.
  *
  * @param \Knp\Menu\ItemInterface $item The item
  *
  * @return boolean|null
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->container->get('request')->getRequestUri()) {
         return true;
     }
     return false;
 }
Пример #12
0
 /**
  * @param \Knp\Menu\ItemInterface $menu        The item to fill with $routes
  * @param array                   $options     The item options
  * @param string                  $currentUri  The current URI
  */
 public function buildCategoryMenu(ItemInterface $menu, array $options = array(), $currentUri = null)
 {
     //$categories = $this->categoryManager->getCategoryTree();
     //$this->fillMenu($menu, $categories, $options, $currentUri);
     $menu->addChild('home', array('route' => 'home'));
     $menu->addChild('home2', array('route' => 'home'));
 }
Пример #13
0
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->request) {
         return null;
     }
     $route = $this->request->attributes->get('_route');
     if (null === $route) {
         return null;
     }
     $routes = (array) $item->getExtra('routes', array());
     $parameters = (array) $item->getExtra('routesParameters', array());
     foreach ($routes as $testedRoute) {
         if (is_string($testedRoute)) {
             $testedRoute = array('route' => $testedRoute);
             // BC layer for the configuration of route params
             if (isset($parameters[$testedRoute['route']])) {
                 $testedRoute['parameters'] = $parameters[$testedRoute['route']];
                 trigger_error('Using the routeParameters extra is deprecated. The parameters should be passed along the route.', E_USER_DEPRECATED);
             }
         }
         if (!is_array($testedRoute)) {
             throw new \InvalidArgumentException('Routes extra items must be strings or arrays.');
         }
         if ($this->isMatchingRoute($testedRoute)) {
             return true;
         }
     }
     return null;
 }
Пример #14
0
 protected function addUserMenu(ItemInterface $menu)
 {
     $menu->addChild('User', array('uri' => '#', 'label' => sprintf('<i class="fa fa-shield"></i> <span>%s</span><i class="fa fa-angle-double-left pull-right"></i></a>', $this->translator->trans('menu.user.title', array(), $this->translationDomain)), 'extras' => array('safe_label' => true), 'attributes' => array('class' => 'treeview')));
     $menu['User']->setChildrenAttribute('class', 'treeview-menu');
     $menu['User']->addChild('Add', array('label' => $this->translator->trans('menu.user.add', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_security_user_new', 'attributes' => array('class' => 'treeview')));
     $menu['User']->addChild('List', array('label' => $this->translator->trans('menu.user.list', array(), $this->translationDomain), 'route' => 'symfonian_indonesia_admin_security_user_list', 'attributes' => array('class' => 'treeview')));
 }
 /**
  * {@inheritDoc}
  */
 public function build(ItemInterface $menu, array $options = array(), $alias = null)
 {
     if (!$this->componentRegistry->hasAllowedProcessor()) {
         return;
     }
     $menu->addChild('orob2b.product.frontend.quick_add.title', ['route' => 'orob2b_product_frontend_quick_add', 'extras' => ['position' => 500, 'description' => 'orob2b.product.frontend.quick_add.description']]);
 }
Пример #16
0
 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge(array('currentClass' => 'active'), $options);
     if ($item->isRoot()) {
         $item->setChildrenAttribute('class', trim('nav navbar-nav ' . $item->getChildrenAttribute('class')));
     }
     return parent::render($item, $options);
 }
 /**
  * Checks whether an item is current.
  *
  * If the voter is not able to determine a result,
  * it should return null to let other voters do the job.
  *
  * @param \Knp\Menu\ItemInterface $item The item
  *
  * @return boolean|null
  */
 public function matchItem(ItemInterface $item)
 {
     $uri = str_replace(array('/', '.'), array('\\/', '\\.'), $item->getUri());
     if (preg_match('/' . $uri . '/', $this->container->get('request')->getRequestUri())) {
         return true;
     }
     return false;
 }
Пример #18
0
 /**
  * Get a flattened array containing references to all of the items
  *
  * @param ItemInterface $item   The menu item
  * @param bool          $isTop  Is the initial menu item starting at the top-level?
  * @return array
  */
 public static function flattenMenuItems(ItemInterface $item, $isTop = true)
 {
     $arr = $isTop ? [] : [$item];
     foreach ($item->getChildren() as $child) {
         $arr = array_merge($arr, self::flattenMenuItems($child, false));
     }
     return $arr;
 }
Пример #19
0
 protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     $admin = $this->isChild() ? $this->getParent() : $this;
     $id = $admin->getRequest()->get('id');
     !$id && $menu->addChild("Refresh currency values", array('uri' => $admin->generateUrl('refresh')));
     parent::configureTabMenu($menu, $action, $childAdmin);
     // TODO: Change the autogenerated stub
 }
 /**
  * @param ItemInterface $menu        The item to fill with $routes
  * @param array         $itemOptions
  */
 public function buildProfileMenu(ItemInterface $menu, array $itemOptions = array())
 {
     foreach ($this->routes as $route) {
         $menu->addChild($this->translator->trans($route['label'], array(), $route['domain']), array_merge($itemOptions, array('route' => $route['route'], 'routeParameters' => $route['route_parameters'])));
     }
     $event = new ProfileMenuEvent($menu);
     $this->eventDispatcher->dispatch('sonata.user.profile.configure_menu', $event);
 }
 protected function addPortfolioLink(ItemInterface $menu)
 {
     $menuItemConfig = ['route' => 'icap_portfolio_index'];
     if ($this->platformConfigHandler->getParameter('portfolio_url')) {
         $menuItemConfig = ['uri' => $this->platformConfigHandler->getParameter('portfolio_url')];
     }
     $menu->addChild($this->translator->trans('my_portfolios', array(), 'icap_portfolio'), $menuItemConfig)->setAttribute('class', 'dropdown')->setAttribute('role', 'presentation')->setExtra('icon', 'fa fa-list-alt');
 }
Пример #22
0
 /**
  * Configures the newly created item's extras
  * Extras are processed one by one in order not to reset values set by other extensions
  *
  * @param ItemInterface $item
  * @param array         $options
  */
 private function buildExtras(ItemInterface $item, array $options)
 {
     if (!empty($options['extras'])) {
         foreach ($options['extras'] as $key => $value) {
             $item->setExtra($key, $value);
         }
     }
 }
Пример #23
0
 protected function configureSideMenu(ItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!$childAdmin && in_array($action, array('edit'))) {
         return;
     }
     $admin = $this->isChild() ? $this->getParent() : $this;
     $menu->addChild('Dodaj zipa', array('uri' => $admin->generateUrl('batch_create')));
 }
Пример #24
0
 protected function configureSideMenu(ItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if ('edit' !== $action) {
         return;
     }
     $page = $this->getSubject();
     $menu->addChild('make-homepage', array('label' => 'Make Homepage', 'attributes' => array('class' => 'btn'), 'route' => 'make_homepage', 'routeParameters' => array('id' => $page->getId())));
 }
Пример #25
0
 public function addCurrent(ItemInterface $menu)
 {
     $currentRoute = $this->stack->getMasterRequest()->get('_route');
     $route = $this->menu[$menu->getName()]['route'];
     if ($currentRoute == $route) {
         $menu->setCurrent(true);
     }
 }
Пример #26
0
 public function decorate(KnpMenuItem $knpMenuItem, AdminMenuItem $adminMenuItem)
 {
     if ($adminMenuItem instanceof RoutableItem && $adminMenuItem->getRoute()) {
         $knpMenuItem->setUri($this->router->generate($adminMenuItem->getRoute(), $adminMenuItem->getRouteParameters()));
         $routes = $knpMenuItem->getExtra('routes', array());
         $routes[] = array('route' => $adminMenuItem->getRoute(), 'parameters' => $adminMenuItem->getRouteParameters());
         $knpMenuItem->setExtra('routes', $routes);
     }
 }
Пример #27
0
 protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     $admin = $this->isChild() ? $this->getParent() : $this;
     $id = $admin->getRequest()->get('id');
     $subject = $this->getSubject();
     $id && $subject && !$subject->getAlias() && $menu->addChild("Translations", array('uri' => $admin->generateUrl('sonata.admin.bordeux.language.translation.list', array('id' => $id))));
     parent::configureTabMenu($menu, $action, $childAdmin);
     // TODO: Change the autogenerated stub
 }
Пример #28
0
 /**
  * {@inheritdoc}
  */
 protected function configureSideMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!$childAdmin && !in_array($action, array('edit'))) {
         return;
     }
     $admin = $this->isChild() ? $this->getParent() : $this;
     $id = $admin->getRequest()->get('id');
     $menu->addChild($this->trans('product.sidemenu.link_product_edit', array(), 'SonataProductBundle'), array('uri' => $admin->generateUrl('edit', array('id' => $id))));
 }
Пример #29
0
 protected function modifyItem(ItemInterface $item, array $options)
 {
     if (!$item->getExtra('remove_leaf', false)) {
         return;
     }
     if (!$item->hasChildren()) {
         $this->removeItem($item);
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function configureTabMenu(MenuItemInterface $menu, $action, AdminInterface $childAdmin = null)
 {
     if (!$childAdmin && !in_array($action, ['list'])) {
         return;
     }
     $menu->addChild('link_queue_list', ['label' => 'Queues', 'attributes' => ['class' => 'btn', 'icon' => 'fa fa-tasks'], 'route' => 'sonata_queue_list']);
     $menu->addChild('link_queue_message_list', ['label' => 'Messages', 'attributes' => ['class' => 'btn', 'icon' => 'fa fa-send'], 'route' => 'sonata_queue_message_list']);
     $menu->addChild('link_queue_log_list', ['label' => 'Exceptions', 'attributes' => ['class' => 'btn', 'icon' => 'fa fa-terminal'], 'route' => 'sonata_queue_log_list']);
 }