-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathModule.php
80 lines (69 loc) · 2.23 KB
/
Module.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace pendalf89\blog;
use Yii;
/**
* Blog module class.
*
* @author Zabolotskikh Boris <[email protected]>
*/
class Module extends \yii\base\Module
{
public $controllerNamespace = 'pendalf89\blog\controllers';
/**
* If true, entered title on create will be translited from
* russian symbols to english automatically on fly.
*
* @var bool auto translit switch.
*/
public $autoTranslit = false;
/**
* @var array options for TinyMCE editor.
* @see http://www.tinymce.com/wiki.php/Plugins
*/
public $editorOptions = [
'language' => 'ru',
'menubar' => false,
'height' => 500,
'image_dimensions' => false,
'plugins' => [
'advlist autolink lists link image charmap print preview anchor searchreplace visualblocks code contextmenu table',
],
'toolbar' => 'undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image | code',
];
/**
* @var string callback function for create post view url. Have $model argument.
*/
public $viewPostUrlCallback = '';
public function init()
{
parent::init();
$this->setDefaultViewPostUrlCallback();
$this->registerTranslations();
}
public function registerTranslations()
{
Yii::$app->i18n->translations['modules/blog/*'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@vendor/pendalf89/yii2-blog/messages',
'fileMap' => [
'modules/blog/main' => 'main.php',
],
];
}
public static function t($category, $message, $params = [], $language = null)
{
if (!isset(Yii::$app->i18n->translations['modules/blog/*'])) {
return $message;
}
return Yii::t("modules/blog/$category", $message, $params, $language);
}
private function setDefaultViewPostUrlCallback()
{
if (empty($this->viewPostUrlCallback)) {
$this->viewPostUrlCallback = function ($model) {
return '#please_set_view_post_url_callback ' . $model->alias;
};
}
}
}