isItemActive() 보호된 메소드

This is done by checking if [[route]] and [[params]] match that specified in the url option of the menu item. When the url option of a menu item is specified in terms of an array, its first element is treated as the route for the item and the rest of the elements are the associated parameters. Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item be considered active.
protected isItemActive ( array $item ) : boolean
$item array the menu item to be checked
리턴 boolean whether the menu item is active
예제 #1
0
파일: Menu.php 프로젝트: oakcms/oakcms
 protected function isItemActive($item)
 {
     if ($item['url'] == Url::to('')) {
         return true;
     } elseif (isset($item['url']) && is_array($item['url']) && isset($item['url'][0])) {
         $route = $item['url'][0];
         if ($route[0] !== '/' && Yii::$app->controller) {
             $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
         }
         if (ltrim($route, '/') !== $this->route) {
             return false;
         }
         unset($item['url']['#']);
         if (count($item['url']) > 1) {
             $params = $item['url'];
             unset($params[0]);
             foreach ($params as $name => $value) {
                 if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                     return false;
                 }
             }
         }
         return true;
     } else {
         return parent::isItemActive($item);
     }
 }
예제 #2
0
 protected function isItemActive($item)
 {
     if (is_string($item['url'])) {
         return $item['url'] === Yii::$app->request->url;
     } else {
         return parent::isItemActive($item);
     }
 }
예제 #3
0
 /**
  * Checks whether a menu item is active.
  * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
  * When the `url` option of a menu item is specified in terms of an array, its first element is treated
  * as the route for the item and the rest of the elements are the associated parameters.
  * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
  * be considered active.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     if (isset($item['urlActive']) && is_array($item['urlActive'])) {
         foreach ($item['urlActive'] as $auxUrl) {
             $auxItem = $item;
             $auxItem['url'] = $auxUrl;
             if (parent::isItemActive($auxItem)) {
                 return true;
             }
         }
     }
     return parent::isItemActive($item);
 }
예제 #4
0
 /**
  * Checks whether a menu item is active.
  * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
  * When the `url` option of a menu item is specified in terms of an array, its first element is treated
  * as the route for the item and the rest of the elements are the associated parameters.
  * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
  * be considered active.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     $res = parent::isItemActive($item);
     if (!$res) {
         $preg = null;
         if (isset($item['preg']) && !empty($item['preg'])) {
             $preg = $item['preg'];
         } elseif (isset($item['url'])) {
             $preg = $item['url'] . ($item['url'] != '/' ? '/*' : '');
         }
         if (!empty($preg)) {
             $preg = '/^' . str_replace('*', '(.*?)', str_replace('/', '\\/', $preg)) . '$/is';
             $res = preg_match($preg, Yii::$app->request->url) || preg_match($preg, Yii::$app->request->url . '/');
         }
     }
     return $res;
 }
예제 #5
0
 /**
  * Checks whether a menu item is active.
  * This is done by checking if [[route]] and [[params]] match that specified in the `url` option of the menu item.
  * When the `url` option of a menu item is specified in terms of an array, its first element is treated
  * as the route for the item and the rest of the elements are the associated parameters.
  * Only when its route and parameters match [[route]] and [[params]], respectively, will a menu item
  * be considered active.
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     $res = parent::isItemActive($item);
     if (!$res && isset($item['activeUrl'])) {
         if (is_array($item['activeUrl'])) {
             $route = $item['activeUrl'][0];
         } else {
             $route = $item['activeUrl'];
         }
         if ($route[0] !== '/' && Yii::$app->controller) {
             $route = Yii::$app->controller->module->getUniqueId() . '/' . $route;
         }
         $route = ltrim($route, '/');
         $preg = '/^' . str_replace('*', '(.*?)', str_replace('/', '\\/', $route)) . '$/is';
         $res = preg_match($preg, $this->route);
     }
     return $res;
 }
예제 #6
0
파일: Menu.php 프로젝트: vetoni/toko
 /**
  * @param array $item
  * @return bool
  */
 protected function isItemActive($item)
 {
     return isset($item['scope']) ? in_array(\Yii::$app->controller->id, $item['scope']) : parent::isItemActive($item);
 }
예제 #7
0
 /**
  * Checks whether a menu item is active.
  * This is true when the module/controller part of the current route matches module/controller part of the provided item.
  * Implemented to activate correct menu when editing record (because there is no menu pointing to these controller actions).
  *
  * @param array $item the menu item to be checked
  * @return boolean whether the menu item is active
  */
 protected function isItemActive($item)
 {
     if (parent::isItemActive($item)) {
         return true;
     }
     $route = Yii::$app->controller->getRoute();
     $route = substr($route, 0, strrpos($route, '/'));
     $menuRoute = trim($item['url'][0], '/');
     if (substr($menuRoute, 0, strrpos($menuRoute, '/')) === $route) {
         return true;
     }
     return false;
 }
예제 #8
0
파일: Menu.php 프로젝트: oakcms/oakcms
 /**
  * @inheritdoc
  */
 protected function isItemActive($item)
 {
     if (isset($item['url']) && is_string($item['url']) && $item['url'] === Url::current()) {
         return true;
     } elseif (isset($item['url'])) {
         if (is_array($item['url'])) {
             $url = $item['url'][0];
         } else {
             $url = $item['url'];
         }
         $url = str_replace("/index", "", $url);
         if (strpos('/' . Yii::$app->request->pathInfo, $url) !== false) {
             return true;
         } else {
             return false;
         }
     } else {
         return parent::isItemActive($item);
     }
 }