You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
1.8 KiB
79 lines
1.8 KiB
6 years ago
|
<?php
|
||
|
|
||
|
namespace common\modules\pages;
|
||
|
|
||
|
use common\modules\pages\widgets\MenuItemCreatorWidget;
|
||
|
use core\components\modules\ModuleInterface;
|
||
|
use yii\helpers\ArrayHelper;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* blog module definition class
|
||
|
*/
|
||
|
class PagesModule extends \yii\base\Module implements ModuleInterface
|
||
|
{
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
public $controllerNamespace = 'common\modules\pages\controllers';
|
||
|
|
||
|
/**
|
||
|
* @inheritdoc
|
||
|
*/
|
||
|
public function init()
|
||
|
{
|
||
|
parent::init();
|
||
|
|
||
|
// custom initialization code goes here
|
||
|
}
|
||
|
|
||
|
public function bootstrap($app)
|
||
|
{
|
||
|
// add search rules
|
||
|
$app->params['search_rules'][] = "SELECT title, content, CONCAT('/pages/manage/page/view/', id) AS url FROM {{pages}}";
|
||
|
|
||
|
$app->getUrlManager()->addRules([
|
||
|
['class' => 'common\modules\pages\urls\PageMainUrlRule'],
|
||
|
]);
|
||
|
|
||
|
$app->getUrlManager()->addRules([
|
||
|
'pages/manage/page/view/<id:\d+>' => 'pages/manage/page/view',
|
||
|
]);
|
||
|
|
||
|
// add languages
|
||
|
$app->getI18n()->translations = ArrayHelper::merge($app->getI18n()->translations, [
|
||
|
'page' => [
|
||
|
'class' => 'yii\i18n\PhpMessageSource',
|
||
|
'basePath' => '@common/modules/pages/messages',
|
||
|
],
|
||
|
'page_public' => [
|
||
|
'class' => 'yii\i18n\PhpMessageSource',
|
||
|
'basePath' => '@common/modules/pages/messages',
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
// add menu items
|
||
|
if (basename($app->getBasePath()) === 'backend') {
|
||
|
$app->params['adminMenu'][] = [
|
||
|
'label' => \Yii::t( 'page', 'Pages' ),
|
||
|
'icon' => 'file-o',
|
||
|
'url' => [ '/pages/manage/page/index' ],
|
||
|
'visible' => \Yii::$app->user->can( 'admin' ) || \Yii::$app->user->can( 'PagesManagement' )
|
||
|
];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static function getMenuItemCreator($menu_id): array
|
||
|
{
|
||
|
$widgets = [];
|
||
|
$widgets[] = [
|
||
|
'id' => 'pages',
|
||
|
'title' => \Yii::t('page', 'Pages'),
|
||
|
'content' => MenuItemCreatorWidget::widget([
|
||
|
'menu_id' => $menu_id,
|
||
|
]),
|
||
|
];
|
||
|
return $widgets;
|
||
|
}
|
||
|
}
|