-
Notifications
You must be signed in to change notification settings - Fork 0
/
Module.php
90 lines (83 loc) · 2.79 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
81
82
83
84
85
86
87
88
89
90
<?php
/**
* @link http://www.diemeisterei.de/
* @copyright Copyright (c) 2018 diemeisterei GmbH, Stuttgart
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace dmstr\activeRecordSearch;
use dmstr\activeRecordSearch\widgets\SearchInput;
use Yii;
/**
* Class Module
* @package dmstr\activeRecordSearch
* Author: Jens Giessmann <[email protected]>
*/
class Module extends \yii\base\Module {
public static $moduleId = 'search';
/**
* callback function that can be used to check if search module is enabled in current context
* @var callable|null
*/
public $enableCallback = null;
/**
* default route for this module
* @var string
*/
public $defaultRoute = 'frontend';
/**
* if set, we add this as theme pathMap in FrontendController
* useful to overwrite just the index.php view for the frontendController of this module
* @var bool
*/
public $frontendViewPath = false;
/**
* layout that should be used in frontendController
* @var string|null
*/
public $frontendLayout = '@frontend/views/layouts/main';
/**
* permission that will be checked in beforeAction within frontendController
* @var string
*/
public $frontendPermission = 'search_frontend';
/**
* permission that will be checked in beforeAction within all "admin" controllers of this module
* @var string
*/
public $adminPermission = 'search_admin';
/**
* permission that will be checked in beforeAction within all api rest controllers
*/
public $apiPermission = 'search_api';
/**
* class that should be used as input widget in frontenController index.php view
* @var string
*/
public $searchInputWidget = SearchInput::class;
/**
* this method wil be called from SearchInput widget to check if search
* module is "enabled" in current context.
*
* @return bool|mixed
*/
public static function isEnabled()
{
// if module is initialised
/** @var \yii\base\Module $class */
$class = self::class;
$module = $class::getInstance();
if ($module && is_callable($module->enableCallback)) {
return call_user_func($module->enableCallback);
}
// if module is defined but not initialised yet
if (!empty(Yii::$app->modules[self::$moduleId])
&& is_array(Yii::$app->modules[self::$moduleId])
&& isset(Yii::$app->modules[self::$moduleId]['enableCallback'])
&& is_callable(Yii::$app->modules[self::$moduleId]['enableCallback'])) {
return call_user_func(Yii::$app->modules[self::$moduleId]['enableCallback']);
}
return true;
}
}