public function matchItem(ItemInterface $item)
 {
     $route = substr($this->container->get('request')->getRequestUri(), 0, strlen($item->getUri()));
     $method = substr(strrchr($this->container->get('request')->getRequestUri(), '/'), 1);
     if ($route == $item->getUri() && ($method == 'modifier' || $method == 'importer' || $method == 'ajouter')) {
         return true;
     }
     return null;
 }
Example #2
0
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->uri || null === $item->getUri()) {
         return null;
     }
     if ($item->getUri() === $this->uri) {
         return true;
     }
     return null;
 }
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->regexp || null === $item->getUri()) {
         return null;
     }
     if (preg_match($this->regexp, $item->getUri())) {
         return true;
     }
     return null;
 }
Example #4
0
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->container->get('request')->getRequestUri()) {
         return true;
     } else {
         if ($item->getUri() !== '/' && substr($this->container->get('request')->getRequestUri(), 0, strlen($item->getUri())) === $item->getUri()) {
             return true;
         }
     }
     return null;
 }
Example #5
0
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->uri || null === $item->getUri()) {
         return null;
     }
     $urlLength = strlen($item->getUri());
     $currentUrlTrimmed = substr($this->uri, 0, $urlLength);
     if ($item->getUri() === $currentUrlTrimmed) {
         return true;
     }
     return null;
 }
Example #6
0
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->container->get('request')->getRequestUri()) {
         // URL's completely match
         return true;
     } else {
         if ($item->getUri() !== $this->container->get('request')->getBaseUrl() . '/' && substr($this->container->get('request')->getRequestUri(), 0, strlen($item->getUri())) === $item->getUri()) {
             // URL isn't just "/" and the first part of the URL match
             return true;
         }
     }
     return null;
 }
Example #7
0
 public function matchItem(ItemInterface $item)
 {
     $request = $this->requestStack->getCurrentRequest();
     if ($item->getUri() === $request->getRequestUri()) {
         // URL's completely match
         return true;
     } else {
         if ($item->getUri() !== $request->getBaseUrl() . '/' && substr($request->getRequestUri(), 0, strlen($item->getUri())) === $item->getUri()) {
             // URL isn't just "/" and the first part of the URL match
             return true;
         }
     }
     return null;
 }
 /**
  * {@inheritDoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if ($item->getUri() === $this->getRequestUri()) {
         return true;
     }
     return null;
 }
 public function render(ItemInterface $item, array $options = array())
 {
     $options = array_merge($this->defaultOptions, $options);
     $translator = $options['translator'];
     $itemIterator = new \Knp\Menu\Iterator\RecursiveItemIterator($item);
     $iterator = new \RecursiveIteratorIterator($itemIterator, \RecursiveIteratorIterator::SELF_FIRST);
     $items = [];
     foreach ($iterator as $item) {
         $translatedLabel = $translator->trans($item->getLabel());
         $id = $item->getName();
         $itemData = ['id' => strtolower($item->getName()), 'name' => $translatedLabel, 'uri' => $item->getUri()];
         $itemData['has_children'] = $item->hasChildren();
         $parentId = $item->getParent()->getName();
         if ($parentId !== $id) {
             $itemData['parent'] = strtolower($parentId);
             if (!isset($items[$parentId]['children'])) {
                 $items[$parentId]['children'] = [];
             }
             $items[$parentId]['children'][] = $itemData;
         }
         if (isset($items[$id])) {
             $items[$id] = array_merge($itemData, $items[$id]);
         } else {
             $items[$id] = $itemData;
         }
     }
     return $items;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * {@inheritDoc}
  */
 public function matchItem(ItemInterface $item)
 {
     if ($prefix = $item->getExtra('prefix_match', $this->defaultActive)) {
         if (strpos($this->getRequestUri(), $item->getUri()) === 0) {
             return true;
         }
     }
     return null;
 }
Example #13
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 ItemInterface $item
  * @return boolean|null
  */
 public function matchItem(ItemInterface $item)
 {
     /* @var $request \Symfony\Component\HttpFoundation\Request */
     $request = $this->container->get('request');
     if ($item->getUri() === $request->getRequestUri()) {
         return true;
     }
     if ($item->getExtra('routes') !== null && in_array($request->attributes->get('_route'), $item->getExtra('routes'))) {
         return true;
     }
     return null;
 }
Example #14
0
 /**
  * @param ItemInterface $item
  *
  * @return bool
  */
 public function matchItem(ItemInterface $item)
 {
     $requestUri = $this->request->getRequestUri();
     $baseUrl = $this->request->getBaseUrl() . '/';
     $uri = $item->getUri();
     if ($uri === $requestUri) {
         return true;
     } else {
         if ($uri !== $baseUrl && substr($requestUri, 0, strlen($uri)) === $uri) {
             return true;
         }
     }
     return null;
 }
Example #15
0
 private function processMenuItem(ItemInterface $menu)
 {
     $uri = $menu->getUri();
     if (!empty($uri) || $uri !== '#') {
         if (false === $this->hasAccess($uri)) {
             $menu->getParent()->removeChild($menu);
             return;
         }
     }
     if ($menu->hasChildren()) {
         foreach ($menu->getChildren() as $item) {
             $this->processMenuItem($item);
         }
     }
     if ((empty($uri) || $uri === '#') && $menu->getName() !== 'root' && !$menu->hasChildren()) {
         $menu->getParent()->removeChild($menu);
     }
 }
Example #16
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 ItemInterface $item
  * @return boolean|null
  */
 public function matchItem(ItemInterface $item)
 {
     /* @var $request \Symfony\Component\HttpFoundation\Request */
     $request = $this->container->get('request');
     if ($item->getUri() === $request->getRequestUri()) {
         return true;
     }
     //        if ($item instanceof \Zym\Bundle\MenuBundle\Entity\MenuItem\RoutedMenuItem) {
     //            /* @var $router \Symfony\Component\Routing\Router */
     //            $router = $this->container->get('router');
     //            $route  = $router->match($request->getPathInfo());
     //
     //            if ($item->getRoute() == $route['_route'] && ) {
     //
     //            }
     //        }
     return null;
 }
 /**
  * Match menu item
  *
  * @param ItemInterface $item Menu item
  *
  * @return bool|null
  */
 public function matchItem(ItemInterface $item)
 {
     if (null === $this->request) {
         return null;
     }
     $controller = $this->request->attributes->get('_controller');
     preg_match('#Controller\\\\([a-zA-Z]*)Controller#', $controller, $matches);
     $controllerName = null;
     if (!empty($matches[1])) {
         $controllerName = mb_strtolower($matches[1], mb_detect_encoding($matches[1]));
     }
     if (empty($controllerName)) {
         return null;
     }
     $route = $item->getUri();
     $routeRequest = $this->request->getBaseUrl() . '/' . $controllerName . '/';
     if ($route == $routeRequest) {
         return true;
     }
     return null;
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     $uri = $item->getExtra('href') ? $item->getExtra('href') : $item->getUri();
     $displayMode = $item->getExtra('display') ? $item->getExtra('display') : 'normal';
     return sprintf('<i class="%s user-action" data-url="%s" data-toggle="tooltip" data-placement="left" title="%s" data-display-mode="%s"></i>', $item->getExtra('icon'), $this->escape($uri), $this->renderLabel($item, $options), $displayMode);
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     $uri = $item->getExtra('href') ? $item->getExtra('href') : $item->getUri();
     return sprintf('<a href="%s">%s</a>', $this->escape($uri), $this->renderLabel($item, $options));
 }
Example #20
0
    /**
     * Renders the link in a a tag with link attributes or
     * the label in a span tag with label attributes
     *
     * Tests if item has a an uri and if not tests if it's
     * the current item and if the text has to be rendered
     * as a link or not.
     *
     * @param \Knp\Menu\ItemInterface $item The item to render the link or label for
     * @param array $options The options to render the item
     * @return string
     */
    public function renderLink(ItemInterface $item, array $options = array())
    {
        $options = array_merge($this->getDefaultOptions(), $options);

        if ($item->getUri() && (!$item->isCurrent() || $options['currentAsLink'])) {
            $text = sprintf('<a href="%s"%s>%s</a>', $this->escape($item->getUri()), $this->renderHtmlAttributes($item->getLinkAttributes()), $this->escape($item->getLabel()));
        } else {
            $text = sprintf('<span%s>%s</span>', $this->renderHtmlAttributes($item->getLabelAttributes()), $this->escape($item->getLabel()));
        }

        return $this->format($text, 'link', $item->getLevel());
    }
Example #21
0
 /**
  * @param \Knp\Menu\ItemInterface $item
  * @param array $options
  * @return null|string
  */
 protected function getUri(ItemInterface $item, array $options)
 {
     if ($item->getUri()) {
         return $item->getUri();
     } elseif ($item->getExtra('link', false) && $this->parentControl) {
         $presenter = $this->parentControl->getPresenter(true);
         return call_user_func_array(array($presenter, 'link'), $item->getExtra('link'));
     }
     return null;
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     $uri = $item->getUri('href') . '?' . $item->getExtra('qstring');
     return sprintf('<a href="%s" title="%s" class="btn btn-default" data-toggle="tooltip" data-placement="bottom" role="button">' . '<i class="%s"></i>' . '</a>', $this->escape($uri), $item->getExtra('title'), $item->getExtra('icon'), $this->renderLabel($item, $options), $item->getExtra('badge'), $item->getExtra('close'));
 }
 protected function renderLink(ItemInterface $item, array $options = array())
 {
     if (!$item->actsLikeLast() && $item->getUri() && (!$item->isCurrent() || $options['currentAsLink'])) {
         $text = $this->renderLinkElement($item, $options);
     } else {
         $text = $this->renderSpanElement($item, $options);
     }
     return $this->format($text, 'link', $item->getLevel(), $options);
 }
Example #24
0
 /**
  * @param ItemInterface $item
  *
  * @return bool
  */
 protected function isItemAllowed(ItemInterface $item)
 {
     return $item->getExtra('isAllowed') && !in_array($item->getUri(), $this->uris) && $item->getUri() !== '#' && $item->isDisplayed();
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     $uri = $item->getExtra('href') ? $item->getExtra('href') : $item->getUri();
     $displayMode = $item->getExtra('display') ? $item->getExtra('display') : 'normal';
     return sprintf('<span class="btn btn-danger btn-lg exception-action-btn text-center" data-url="%s" data-display-mode="%s">' . '%s' . '</span>', $this->escape($uri), $displayMode, $this->renderLabel($item, $options));
 }
Example #26
0
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     $uri = $item->getExtra('href') ? $item->getExtra('href') : $item->getUri();
     return sprintf('<a role="menuitem" href="%s" title="%s"><i class="%s"></i><span class="break-hide"> %s</span> <span class="badge">%s</span></a><div>%s</div>', $this->escape($uri), $item->getExtra('title'), $item->getExtra('icon'), $this->renderLabel($item, $options), $item->getExtra('badge'), $item->getExtra('close'));
 }
 private function getBreadcrumbsItem(ItemInterface $item)
 {
     return array('label' => $item->getLabel(), 'uri' => $item->getUri(), 'item' => $item);
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     return sprintf('<a href="%s"%s>%s</span></a>', $this->escape($item->getUri()), $this->renderHtmlAttributes($item->getLinkAttributes()), $this->renderLabel($item, $options));
 }
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     return sprintf('<a href="%s" class="list-group-item">%s</a>', $this->escape($item->getUri()), $this->renderLabel($item, $options));
 }
Example #30
0
 protected function renderLinkElement(ItemInterface $item, array $options)
 {
     return sprintf('<a role="menuitem" href="%s"><i class="%s"></i><span> %s</span></a>', $this->escape($item->getUri() . $item->getExtra('uri-add')), $item->getExtra('icon'), $this->renderLabel($item, $options));
 }