backend/widgets/Menu.php
/**
     * 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
     */
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
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['url']) && is_array($item['url']) && isset($item['url'][0])) {
            $route = $item['url'][0];
            if ($route[0] !== '/' && Yii::$app->controller) {
                $route = ltrim(Yii::$app->controller->module->getUniqueId() . '/' . $route, '/');
            }
            $route = ltrim($route, '/');
            $itemBaseRoute = str_replace('/index', '', $route);
            $currentBaseRoute = str_replace('/index', '', $this->route);
            $currentBaseRoute =  str_replace(array_map(function ($value) {
                return ($value[0] === '/' ? $value : '/' . $value);
            }, $this->crudActions), '', $currentBaseRoute);
            if (!empty($item['hides'])) {
                foreach ($item['hides'] as $hide) {
                    $hide = ltrim($hide, '/');
                    $hide = str_replace('/index', '', $hide);
                    if ($hide == $currentBaseRoute) {
                        return true;
                    }
                }
            }
            if ($route !== $this->route && $itemBaseRoute != $currentBaseRoute && $itemBaseRoute !== $this->noDefaultRoute && $itemBaseRoute !== $this->noDefaultAction) {
                return false;
            }
            unset($item['url']['#']);
            if (count($item['url']) > 1) {
                foreach (array_splice($item['url'], 1) as $name => $value) {
                    if ($value !== null && (!isset($this->params[$name]) || $this->params[$name] != $value)) {
                        return false;
                    }
                }
            }
            return true;
        }
        return false;
    }
protected function isItemActive ( $ item ) { if ( isset ( $ item [ 'url' ] ) && is_array ( $ item [ 'url' ] ) && isset ( $ item [ 'url' ] [ 0 ] ) ) { $ route = $ item [ 'url' ] [ 0 ] ; if ( $ route [ 0 ] !== '/' && Yii :: $ app -> controller ) { $ route = ltrim ( Yii :: $ app -> controller -> module -> getUniqueId ( ) . '/' . $ route , '/' ) ; } $ route = ltrim ( $ route , '/' ) ; $ itemBaseRoute = str_replace ( '/index' , '' , $ route ) ; $ currentBaseRoute = str_replace ( '/index' , '' , $ this -> route ) ; $ currentBaseRoute = str_replace ( array_map ( function ( $ value ) { return ( $ value [ 0 ] === '/' ? $ value : '/' . $ value ) ; } , $ this -> crudActions ) , '' , $ currentBaseRoute ) ; if ( ! empty ( $ item [ 'hides' ] ) ) { foreach ( $ item [ 'hides' ] as $ hide ) { $ hide = ltrim ( $ hide , '/' ) ; $ hide = str_replace ( '/index' , '' , $ hide ) ; if ( $ hide == $ currentBaseRoute ) { return true ; } } } if ( $ route !== $ this -> route && $ itemBaseRoute != $ currentBaseRoute && $ itemBaseRoute !== $ this -> noDefaultRoute && $ itemBaseRoute !== $ this -> noDefaultAction ) { return false ; } unset ( $ item [ 'url' ] [ '#' ] ) ; if ( count ( $ item [ 'url' ] ) > 1 ) { foreach ( array_splice ( $ item [ 'url' ] , 1 ) as $ name => $ value ) { if ( $ value !== null && ( ! isset ( $ this -> params [ $ name ] ) || $ this -> params [ $ name ] != $ value ) ) { return false ; } } } return true ; } return false ; }
Checks whether a menu item is active.
Checks whether a menu item is active .
// Сравниваем два базовых маршрута