luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
811 stars 205 forks source link

The menu id of module #1796

Closed baqianxin closed 6 years ago

baqianxin commented 6 years ago
  /**
     * Invokes the bootstraping process.
     *
     * @see \luya\base\BaseBootstrap::run()
     */
    public function run($app)
    {
        if (!$app->request->getIsConsoleRequest()) {
            if ($this->hasModule('admin') && $app->request->isAdmin) {
                // When admin context, change csrf token, this will not terminate the frontend csrf token:
                // @see https://github.com/luyadev/luya/issues/1778
                $app->request->csrfParam = '_csrf_admin';

                foreach ($this->getModules() as $id => $module) {
                    if ($module instanceof AdminModuleInterface) {
                        $this->_adminAssets = ArrayHelper::merge($module->getAdminAssets(), $this->_adminAssets);
                        if ($module->getMenu()) {
                            $this->_adminMenus[$module->id] = $module->getMenu();
                        }
                        $this->_jsTranslations[$id] = $module->getJsTranslationMessages();
                    }
                }

                $app->getModule('admin')->assets = $this->_adminAssets;
                $app->getModule('admin')->controllerMap = $this->_apis;
                $app->getModule('admin')->moduleMenus = $this->_adminMenus;
                $app->getModule('admin')->setJsTranslations($this->_jsTranslations);
            }
        }

        $app->getUrlManager()->addRules($this->_urlRules);
    }

    /**
     * The menu object from the {{\luya\admin\components\AdminMenuBuilder}} class in order to store and build the administration
     * module menu elements.
     *
     * @return false|\luya\admin\components\AdminMenuBuilderInterface
     */
    public function getMenu()
    {
        $this->id='admin';//i can use the id to reset the admin menu @nadar
        return (new AdminMenuBuilder($this))
            ->node('API管理', 'extension')
            ->group('Group')
            ->itemApi('授权用户', 'apiadmin/api-auth-user/index', 'poll', 'api-auth-user');
    }

@nadar ,but i think we shoud provide the $module->getMenuID() instand of the module->id

$this->_adminMenus[$module->id] = $module->getMenu(); $this->_adminMenus[$module->getMenuID()] = $module->getMenu();

nadar commented 6 years ago

I like the idea of injecting items to an existing menu node, but maybe we should create another solution for this use case. Maybe we can close this issue here and create an issue in the admin module with a description of what we try to do and what would be the best approach to achieve it. Agree?