-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
103 lines (82 loc) · 2.71 KB
/
Plugin.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
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php namespace BnB\UserGroup;
use Backend\Facades\Backend;
use Illuminate\Support\Facades\Event;
use RainLab\User\Components\Session;
use RainLab\User\Models\User;
use System\Classes\PluginBase;
/**
* UserGroup Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = [
'RainLab.User'
];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'bnb.usergroup::lang.plugin.name',
'description' => 'bnb.usergroup::lang.plugin.description',
'author' => 'B&B Web Expertise',
'icon' => 'icon-users'
];
}
public function registerPermissions()
{
return [
'rainlab.groups.access_groups' => [
'tab' => 'rainlab.user::lang.plugin.tab',
'label' => 'bnb.usergroup::lang.plugin.access_groups'
]
];
}
public function registerComponents()
{
return [
'BnB\UserGroup\Components\SessionGroup' => 'SessionGroup'
];
}
public function boot()
{
Session::extend(function ($component) {
/* @var $component Session */
});
User::extend(function ($model) {
/* @var $model User */
$model->belongsToMany['groups'] = ['BnB\UserGroup\Models\UserGroup', 'table' => 'users_groups'];
});
Event::listen('backend.menu.extendItems', function ($manager) {
$manager->addSideMenuItems('RainLab.User', 'user', [
'groups' => [
'label' => 'bnb.usergroup::lang.groups.all_groups',
'icon' => 'icon-users',
'url' => Backend::url('bnb/usergroup/usergroups'),
'permissions' => ['rainlab.groups.access_groups']
]
]);
});
Event::listen('backend.form.extendFields', function ($widget) {
//Extend groups controller
if ( ! $widget->getController() instanceof \RainLab\User\Controllers\Users) {
return;
}
if ( ! $widget->model instanceof \RainLab\User\Models\User) {
return;
}
$widget->addTabFields([
'groups' => [
'label' => trans('bnb.usergroup::lang.user.groups'),
'comment' => trans('bnb.usergroup::lang.user.groups_comment'),
'type' => 'relation',
'tab' => 'bnb.usergroup::lang.user.groups',
'span' => 'auto'
]
]);
});
}
}