src/components/AdminMenu.php
public function getModules()
    {
        if ($this->_modules !== null) {
            return $this->_modules;
        }
        
        $responseData = [];
        foreach ($this->getMenu() as $item) {
            // check if this is an entrie with a permission
            if ($item['permissionIsRoute']) {
                // verify if the permission is provided for this user:
                // if the permission is granted will write inti $responseData,
                // if not we continue;
                if (!Yii::$app->auth->matchRoute($this->getUserId(), $item['permissionRoute'])) {
                    continue;
                }
            }

            // this item does have groups
            if (isset($item['groups'])) {
                $permissionGranted = false;

                // see if the groups has items
                foreach ($item['groups'] as $groupName => $groupItem) {
                    if (count($groupItem['items'])  > 0) {
                        if ($permissionGranted) {
                            continue;
                        }

                        foreach ($groupItem['items'] as $groupItemEntry) {
                            // a previous entry already has solved the question if the permission is granted
                            if ($permissionGranted) {
                                continue;
                            }
                            if ($groupItemEntry['permissionIsRoute']) {
                                // when true, set permissionGranted to true
                                if (Yii::$app->auth->matchRoute($this->getUserId(), $groupItemEntry['route'])) {
                                    $permissionGranted = true;
                                }
                            } elseif ($groupItemEntry['permissionIsApi']) {
                                // when true, set permissionGranted to true
                                if (Yii::$app->auth->matchApi($this->getUserId(), $groupItemEntry['permissionApiEndpoint'])) {
                                    $permissionGranted = true;
                                }
                            } else {
                                throw new Exception('Menu item detected without permission entry');
                            }
                        }
                    }
                }

                if (!$permissionGranted) {
                    continue;
                }
            }
            
            try {
                // check if a translation exists, otherwise use alias instead.
                $alias = Yii::t($item['moduleId'], $item['alias'], [], Yii::$app->language);
            } catch (\Exception $err) {
                $alias = $item['alias'];
            }
            
            // ok we have passed all the tests, lets make an entry
            $responseData[] = [
                'moduleId' => $item['moduleId'],
                'id' => $item['id'],
                'template' => $item['template'],
                'routing' => $item['routing'],
                'alias' => $alias,
                'icon' => $item['icon'],
                'searchModelClass' => $item['searchModelClass'],

            ];
        }

        $this->_modules = $responseData;

        return $responseData;
    }
public function getModules()
    {
        if ($this->_modules !== null) {
            return $this->_modules;
        }
        
        $responseData = [];
        foreach ($this->getMenu() as $item) {
            // check if this is an entrie with a permission
            if ($item['permissionIsRoute']) {
                // verify if the permission is provided for this user:
                // if the permission is granted will write inti $responseData,
                // if not we continue;
                if (!Yii::$app->auth->matchRoute($this->getUserId(), $item['permissionRoute'])) {
                    continue;
                }
            }

            // this item does have groups
            if (isset($item['groups'])) {
                $permissionGranted = false;

                // see if the groups has items
                foreach ($item['groups'] as $groupName => $groupItem) {
                    if (count($groupItem['items'])  > 0) {
                        if ($permissionGranted) {
                            continue;
                        }

                        foreach ($groupItem['items'] as $groupItemEntry) {
                            // a previous entry already has solved the question if the permission is granted
                            if ($permissionGranted) {
                                continue;
                            }
                            if ($groupItemEntry['permissionIsRoute']) {
                                // when true, set permissionGranted to true
                                if (Yii::$app->auth->matchRoute($this->getUserId(), $groupItemEntry['route'])) {
                                    $permissionGranted = true;
                                }
                            } elseif ($groupItemEntry['permissionIsApi']) {
                                // when true, set permissionGranted to true
                                if (Yii::$app->auth->matchApi($this->getUserId(), $groupItemEntry['permissionApiEndpoint'])) {
                                    $permissionGranted = true;
                                }
                            } else {
                                throw new Exception('Menu item detected without permission entry');
                            }
                        }
                    }
                }

                if (!$permissionGranted) {
                    continue;
                }
            }
            
            try {
                // check if a translation exists, otherwise use alias instead.
                $alias = Yii::t($item['moduleId'], $item['alias'], [], Yii::$app->language);
            } catch (\Exception $err) {
                $alias = $item['alias'];
            }
            
            // ok we have passed all the tests, lets make an entry
            $responseData[] = [
                'moduleId' => $item['moduleId'],
                'id' => $item['id'],
                'template' => $item['template'],
                'routing' => $item['routing'],
                'alias' => $alias,
                'icon' => $item['icon'],
                'searchModelClass' => $item['searchModelClass'],

            ];
        }

        $this->_modules = $responseData;

        return $responseData;
    }
public function getModules ( ) { if ( $ this -> _modules !== null ) { return $ this -> _modules ; } $ responseData = [ ] ; foreach ( $ this -> getMenu ( ) as $ item ) { // check if this is an entrie with a permission if ( $ item [ 'permissionIsRoute' ] ) { // verify if the permission is provided for this user: // if the permission is granted will write inti $responseData, // if not we continue; if ( ! Yii :: $ app -> auth -> matchRoute ( $ this -> getUserId ( ) , $ item [ 'permissionRoute' ] ) ) { continue ; } } // this item does have groups if ( isset ( $ item [ 'groups' ] ) ) { $ permissionGranted = false ; // see if the groups has items foreach ( $ item [ 'groups' ] as $ groupName => $ groupItem ) { if ( count ( $ groupItem [ 'items' ] ) > 0 ) { if ( $ permissionGranted ) { continue ; } foreach ( $ groupItem [ 'items' ] as $ groupItemEntry ) { // a previous entry already has solved the question if the permission is granted if ( $ permissionGranted ) { continue ; } if ( $ groupItemEntry [ 'permissionIsRoute' ] ) { // when true, set permissionGranted to true if ( Yii :: $ app -> auth -> matchRoute ( $ this -> getUserId ( ) , $ groupItemEntry [ 'route' ] ) ) { $ permissionGranted = true ; } } elseif ( $ groupItemEntry [ 'permissionIsApi' ] ) { // when true, set permissionGranted to true if ( Yii :: $ app -> auth -> matchApi ( $ this -> getUserId ( ) , $ groupItemEntry [ 'permissionApiEndpoint' ] ) ) { $ permissionGranted = true ; } } else { throw new Exception ( 'Menu item detected without permission entry' ) ; } } } } if ( ! $ permissionGranted ) { continue ; } } try { // check if a translation exists, otherwise use alias instead. $ alias = Yii :: t ( $ item [ 'moduleId' ] , $ item [ 'alias' ] , [ ] , Yii :: $ app -> language ) ; } catch ( \ Exception $ err ) { $ alias = $ item [ 'alias' ] ; } // ok we have passed all the tests, lets make an entry $ responseData [ ] = [ 'moduleId' => $ item [ 'moduleId' ] , 'id' => $ item [ 'id' ] , 'template' => $ item [ 'template' ] , 'routing' => $ item [ 'routing' ] , 'alias' => $ alias , 'icon' => $ item [ 'icon' ] , 'searchModelClass' => $ item [ 'searchModelClass' ] , ] ; } $ this -> _modules = $ responseData ; return $ responseData ; }
Returns an Array with modules and checks the permission for those.

Example Response:

```php
Array (
'moduleId' => 'admin',
'id' => 1,
'template' => $item['template'],
'routing' => $item['routing'],
'alias' => $alias,
'icon' => $item['icon'],
'searchModelClass' => $item['searchModelClass'],
)
```

@throws Exception
@return array Returns an array with all modules you have permission for.
Returns an Array with modules and checks the permission for those .