Example #1
0
 /**
  * Add new link
  *
  * @param string $text
  * @param array  $url
  * @param array  $options
  *
  * @return Menu
  */
 public function addLink($text, array $url = [], $options = [])
 {
     $linkUrl = '#';
     $defaultIsActive = false;
     if ($to = array_get($url, 'to')) {
         $linkUrl = $this->manager->getUrl()->to($to);
     } elseif ($route = array_get($url, 'route')) {
         if (!is_array($route)) {
             $route = [$route];
         }
         $routeName = array_shift($route);
         $routeParams = $route;
         $linkUrl = $this->manager->getUrl()->route($routeName, $routeParams);
         $defaultIsActive = ['route' => $routeName, 'route_param' => $routeParams];
     } elseif ($action = array_get($url, 'action')) {
         if (!is_array($action)) {
             $action = [$action];
         }
         $actionName = array_shift($action);
         $linkUrl = $this->manager->getUrl()->action($actionName, $action);
         $defaultIsActive = ['action' => $actionName, 'route_param' => $action];
     }
     if ($query = array_get($url, 'query')) {
         $linkUrl .= '?' . http_build_query($query);
         $defaultIsActive['query'] = $query;
     }
     if (!isset($options['url_def'])) {
         $options['url_def'] = $defaultIsActive;
     }
     $this->addItem(['text' => $text, 'url' => $linkUrl], $options);
     return $this;
 }