From ec14ba429ca25832e6159ce9450768071ccb3266 Mon Sep 17 00:00:00 2001 From: Egorka Date: Tue, 4 Sep 2018 13:09:09 +0300 Subject: [PATCH] Admin menu fix --- backend/views/layouts/left.php | 264 +++++++++++++++++++++++++++-------------- common/bootstrap/SetUp.php | 80 +++++++------ 2 files changed, 214 insertions(+), 130 deletions(-) diff --git a/backend/views/layouts/left.php b/backend/views/layouts/left.php index 0981cd5..bb73075 100644 --- a/backend/views/layouts/left.php +++ b/backend/views/layouts/left.php @@ -15,7 +15,8 @@ $model = new SearchForm();
- <?= Yii::$app->user->identity->user->username ?> + <?= Yii::$app->user->identity->user->username ?>

user->identity->user->username ?>

@@ -24,102 +25,183 @@ $model = new SearchForm();
- - \yii\helpers\Url::to(['/site/search']), - 'options' => [ - 'class' => 'sidebar-form' - ], - 'enableClientValidation' => false, - 'fieldConfig' => [ - 'options' => [ - 'tag' => false, - ], - ], - ]); ?> - - field($model, 'query', [ - 'addon' => [ - 'append' => [ - 'content' => Html::button('', ['class'=>'btn btn-flat', 'id' => 'search-btn']), - 'asButton' => true - ] - ], - 'template' => "{input}", - ])->textInput(['placeholder' => Yii::t('main', 'Search...')])->label(false)->hint(false); ?> - - + + \yii\helpers\Url::to(['/site/search']), + 'options' => [ + 'class' => 'sidebar-form' + ], + 'enableClientValidation' => false, + 'fieldConfig' => [ + 'options' => [ + 'tag' => false, + ], + ], + ]); ?> + + field($model, 'query', [ + 'addon' => [ + 'append' => [ + 'content' => Html::button('', ['class' => 'btn btn-flat', 'id' => 'search-btn']), + 'asButton' => true + ] + ], + 'template' => "{input}", + ])->textInput(['placeholder' => Yii::t('main', 'Search...')])->label(false)->hint(false); ?> + + ['class' => 'sidebar-menu tree', 'data-widget'=> 'tree'], - 'items' => \yii\helpers\ArrayHelper::merge([ + 'options' => ['class' => 'sidebar-menu tree', 'data-widget' => 'tree'], + 'items' => \yii\helpers\ArrayHelper::merge([ ['label' => Yii::t('main', 'Menu'), 'options' => ['class' => 'header']], - [ - 'label' => Yii::t('dashboard', 'Dashboard'), - 'icon' => 'dashboard', - 'url' => ['/site/index'], - 'active' => $this->context->id == '/site/index'], - - [ - 'label' => Yii::t('user', 'Users'), - 'icon' => 'user', - 'url' => ['/user/index'], - 'active' => $this->context->id == 'user', - 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('UserManagement'), - ], - - ['label' => Yii::t('user', 'Access Rules'), 'icon' => 'lock', 'items' => [ - ['label' => Yii::t('user', 'Roles'), 'icon' => 'caret-right', 'url' => ['/role/index'], 'active' => \Yii::$app->controller->getUniqueId() == 'role'], - ['label' => Yii::t('user', 'Permissions'), 'icon' => 'caret-right', 'url' => ['/permission/index'], 'active' => \Yii::$app->controller->getUniqueId() == 'permission'], - ], 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('UserManagement')], - - [ - 'label' => Yii::t('menu', 'Menu'), - 'icon' => 'bars', 'url' => ['/menu/index'], - 'active' => $this->context->id == 'menu', - 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('MenuManagement'), - ], - - ['label' => Yii::t('main', 'Modules'), 'icon' => 'cubes', 'items' => [ - ['label' => Yii::t('main', 'Modules'), 'icon' => 'caret-right', 'url' => ['/module/list'], 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/list'], - ['label' => Yii::t('main', 'Find modules'), 'icon' => 'caret-right', 'url' => ['/module/search'], 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/search'], - ], 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('ModuleManagement')], - - /*[ - 'label' => Yii::t('pages', 'Pages'), - 'icon' => 'file-o', 'url' => ['/page/index'], - 'active' => $this->context->id == 'page', - 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('PagesManagement'), - ],*/ - - ['label' => Yii::t('post', 'Posts'), 'icon' => 'newspaper-o', 'items' => array_merge( - array_map(function(\core\entities\post\PostType $type) { - return ['label' => $type->plural, 'icon' => 'caret-right', 'items' => [ - ['label' => Yii::t('post', 'Categories'), 'icon' => 'caret-right', 'url' => ['/post/category', 'tid' => $type->id], 'active' => \Yii::$app->controller->getUniqueId() == 'post/category' && \Yii::$app->request->get('tid') == $type->id], - ['label' => $type->plural, 'icon' => 'caret-right', 'url' => ['/post/post', 'tid' => $type->id], 'active' => \Yii::$app->controller->getUniqueId() == 'post/post' && \Yii::$app->request->get('tid') == $type->id], - ['label' => Yii::t('post', 'Tags'), 'icon' => 'caret-right', 'url' => ['/post/tag', 'tid' => $type->id], 'active' => \Yii::$app->controller->getUniqueId() == 'post/tag' && \Yii::$app->request->get('tid') == $type->id], - ]]; - }, \core\entities\post\PostType::find()->all()), - [['label' => Yii::t('post', 'Comments'), 'icon' => 'caret-right', 'url' => ['/post/comment'], 'active' => \Yii::$app->controller->getUniqueId() == 'post/comment']], - [['label' => Yii::t('post', 'Types'), 'icon' => 'caret-right', 'url' => ['/post/type'], 'active' => \Yii::$app->controller->getUniqueId() == 'post/type']] - ), 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('PostManagement')], - - [ - 'label' => Yii::t('slider', 'Slider'), - 'icon' => 'retweet', 'url' => ['/slider/index'], - 'active' => $this->context->id == 'slider', - 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('SliderManagement'), - ], - - ['label' => Yii::t('main', 'Settings'), 'icon' => 'cog', 'items' => [ - ['label' => Yii::t('main', 'Settings List'), 'icon' => 'caret-right', 'url' => ['/settings/list/index'], 'active' => \Yii::$app->controller->getUniqueId() == 'settings/list'], - //['label' => Yii::t('main', 'Find modules'), 'icon' => 'caret-right', 'url' => ['/module/search'], 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/search'], - ], 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('SettingsManagement')], - - ], Yii::$app->params['adminMenu']), + [ + 'label' => Yii::t('dashboard', 'Dashboard'), + 'icon' => 'dashboard', + 'url' => ['/site/index'], + 'active' => $this->context->id == '/site/index' + ], + + [ + 'label' => Yii::t('user', 'Users'), + 'icon' => 'user', + 'url' => ['/user/index'], + 'active' => $this->context->id == 'user', + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('UserManagement'), + ], + + [ + 'label' => Yii::t('user', 'Access Rules'), + 'icon' => 'lock', + 'items' => [ + [ + 'label' => Yii::t('user', 'Roles'), + 'icon' => 'caret-right', + 'url' => ['/role/index'], + 'active' => \Yii::$app->controller->getUniqueId() == 'role' + ], + [ + 'label' => Yii::t('user', 'Permissions'), + 'icon' => 'caret-right', + 'url' => ['/permission/index'], + 'active' => \Yii::$app->controller->getUniqueId() == 'permission' + ], + ], + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('UserManagement') + ], + + [ + 'label' => Yii::t('menu', 'Menu'), + 'icon' => 'bars', + 'url' => ['/menu/index'], + 'active' => $this->context->id == 'menu', + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('MenuManagement'), + ], + + [ + 'label' => Yii::t('main', 'Modules'), + 'icon' => 'cubes', + 'items' => [ + [ + 'label' => Yii::t('main', 'Modules'), + 'icon' => 'caret-right', + 'url' => ['/module/list'], + 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/list' + ], + [ + 'label' => Yii::t('main', 'Find modules'), + 'icon' => 'caret-right', + 'url' => ['/module/search'], + 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/search' + ], + ], + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('ModuleManagement') + ], + + /*[ + 'label' => Yii::t('pages', 'Pages'), + 'icon' => 'file-o', 'url' => ['/page/index'], + 'active' => $this->context->id == 'page', + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('PagesManagement'), + ],*/ + + [ + 'label' => Yii::t('post', 'Posts'), + 'icon' => 'newspaper-o', + 'items' => array_merge( + array_map(function (\core\entities\post\PostType $type) { + return [ + 'label' => $type->plural, + 'icon' => 'caret-right', + 'items' => [ + [ + 'label' => Yii::t('post', 'Categories'), + 'icon' => 'caret-right', + 'url' => ['/post/category', 'tid' => $type->id], + 'active' => \Yii::$app->controller->getUniqueId() == 'post/category' && \Yii::$app->request->get('tid') == $type->id + ], + [ + 'label' => $type->plural, + 'icon' => 'caret-right', + 'url' => ['/post/post', 'tid' => $type->id], + 'active' => \Yii::$app->controller->getUniqueId() == 'post/post' && \Yii::$app->request->get('tid') == $type->id + ], + [ + 'label' => Yii::t('post', 'Tags'), + 'icon' => 'caret-right', + 'url' => ['/post/tag', 'tid' => $type->id], + 'active' => \Yii::$app->controller->getUniqueId() == 'post/tag' && \Yii::$app->request->get('tid') == $type->id + ], + ] + ]; + }, \core\entities\post\PostType::find()->all()), + [ + [ + 'label' => Yii::t('post', 'Comments'), + 'icon' => 'caret-right', + 'url' => ['/post/comment'], + 'active' => \Yii::$app->controller->getUniqueId() == 'post/comment' + ] + ], + [ + [ + 'label' => Yii::t('post', 'Types'), + 'icon' => 'caret-right', + 'url' => ['/post/type'], + 'active' => \Yii::$app->controller->getUniqueId() == 'post/type' + ] + ] + ), + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('PostManagement') + ], + + [ + 'label' => Yii::t('slider', 'Slider'), + 'icon' => 'retweet', + 'url' => ['/slider/index'], + 'active' => $this->context->id == 'slider', + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('SliderManagement'), + ], + + [ + 'label' => Yii::t('main', 'Settings'), + 'icon' => 'cog', + 'items' => [ + [ + 'label' => Yii::t('main', 'Settings List'), + 'icon' => 'caret-right', + 'url' => ['/settings/list/index'], + 'active' => \Yii::$app->controller->getUniqueId() == 'settings/list' + ], + //['label' => Yii::t('main', 'Find modules'), 'icon' => 'caret-right', 'url' => ['/module/search'], 'active' => \Yii::$app->controller->action->getUniqueId() == 'module/search'], + ], + 'visible' => \Yii::$app->user->can('admin') || \Yii::$app->user->can('SettingsManagement') + ], + + ], (isset(Yii::$app->params['adminMenu']) && is_array(Yii::$app->params['adminMenu']) ? Yii::$app->params['adminMenu'] : [])), ] ) ?> diff --git a/common/bootstrap/SetUp.php b/common/bootstrap/SetUp.php index 7a080c7..d99e584 100644 --- a/common/bootstrap/SetUp.php +++ b/common/bootstrap/SetUp.php @@ -7,6 +7,7 @@ namespace common\bootstrap; //use core\components\modules\ModuleInterface; use common\modules\languages\entities\Language; use core\entities\ModuleRecord; + //use League\Flysystem\Adapter\Ftp; //use League\Flysystem\Filesystem; //use shop\cart\Cart; @@ -17,16 +18,19 @@ use core\dispatchers\AsyncEventDispatcher; use core\dispatchers\DeferredEventDispatcher; use core\dispatchers\EventDispatcher; use core\dispatchers\SimpleEventDispatcher; + //use core\entities\behaviors\FlySystemImageUploadBehavior; //use shop\entities\Shop\Product\events\ProductAppearedInStock; use core\jobs\AsyncEventJobHandler; use core\listeners\user\UserSignupConfirmedListener; use core\listeners\user\UserSignupRequestedListener; + //use shop\repositories\events\EntityPersisted; //use shop\repositories\events\EntityRemoved; use core\services\newsletter\FakeSubscribe; use core\services\newsletter\MailChimp; use core\services\newsletter\Newsletter; + //use shop\services\sms\LoggedSender; //use shop\services\sms\SmsRu; //use shop\services\sms\SmsSender; @@ -140,47 +144,45 @@ class SetUp implements BootstrapInterface $container->set(ImageUploadBehavior::class, FlySystemImageUploadBehavior::class); */ - // Set frontend languages - if (\Yii::$app->moduleManager->isTableExist('{{%languages}}') && file_exists(Yii::getAlias('@common/modules/languages/LanguagesModule.php'))) { - $language = Language::find()->active()->default()->one(); - Yii::$app->params['defaultLanguage'] = $language ? $language->name : 'ru'; - Yii::$app->params['translatedLanguages'] = ArrayHelper::map( Language::find()->active()->all(), 'name', 'title' ); - } - else { - Yii::$app->params['defaultLanguage'] = 'en'; - Yii::$app->params['translatedLanguages'] = ['en']; - } - - // Set backend languages - if (basename($app->getBasePath()) === 'backend') { - $app->language = ! $app->user->isGuest && $app->user->identity->user->backend_language ? $app->user->identity->user->backend_language : Yii::$app->params['defaultLanguage']; - $app->params['frontendLanguage'] = Yii::$app->session->get('frontendLanguage', Yii::$app->params['defaultLanguage']); - } + // Set frontend languages + if (\Yii::$app->moduleManager->isTableExist('{{%languages}}') && file_exists(Yii::getAlias('@common/modules/languages/LanguagesModule.php'))) { + $language = Language::find()->active()->default()->one(); + Yii::$app->params['defaultLanguage'] = $language ? $language->name : 'ru'; + Yii::$app->params['translatedLanguages'] = ArrayHelper::map(Language::find()->active()->all(), 'name', 'title'); + } else { + Yii::$app->params['defaultLanguage'] = 'en'; + Yii::$app->params['translatedLanguages'] = ['en']; + } + + // Set backend languages + if (basename($app->getBasePath()) === 'backend') { + $app->language = !$app->user->isGuest && $app->user->identity->user->backend_language ? $app->user->identity->user->backend_language : Yii::$app->params['defaultLanguage']; + $app->params['frontendLanguage'] = Yii::$app->session->get('frontendLanguage', Yii::$app->params['defaultLanguage']); + } // Connect common modules - if (\Yii::$app->moduleManager->isTableExist('{{%modules}}')) { - $modules = ModuleRecord::find()->andWhere(['type' => 'common'])->andWhere(['active' => 1])->all(); - foreach ($modules as $module) { - Yii::$app->setModule($module->name, [ - 'class' => $module->class, - ]); - Yii::$app->getModule($module->name)->bootstrap(Yii::$app); - } - } - else { // connect all existing modules - $this->connectExistingModules(); - } + if (\Yii::$app->moduleManager->isTableExist('{{%modules}}')) { + $modules = ModuleRecord::find()->andWhere(['type' => 'common'])->andWhere(['active' => 1])->all(); + foreach ($modules as $module) { + Yii::$app->setModule($module->name, [ + 'class' => $module->class, + ]); + Yii::$app->getModule($module->name)->bootstrap(Yii::$app); + } + } else { // connect all existing modules + $this->connectExistingModules(); + } } - private function connectExistingModules(): void - { - $modules = Yii::$app->moduleManager->getLocalModules(); - //print_r($modules); die; - foreach ($modules as $module) { - Yii::$app->setModule($module['name'], [ - 'class' => 'common\modules\\' . $module['name'] . '\\' . $module['module'], - ]); - Yii::$app->getModule( $module['name'] )->bootstrap( Yii::$app ); - } - } + private function connectExistingModules(): void + { + $modules = Yii::$app->moduleManager->getLocalModules(); + //print_r($modules); die; + foreach ($modules as $module) { + Yii::$app->setModule($module['name'], [ + 'class' => 'common\modules\\' . $module['name'] . '\\' . $module['module'], + ]); + Yii::$app->getModule($module['name'])->bootstrap(Yii::$app); + } + } } \ No newline at end of file