1 | <?php |
||
34 | class Organization extends BasePlugin |
||
35 | { |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | public $controllerMap = [ |
||
41 | 'save' => [ |
||
42 | 'class' => OrganizationController::class, |
||
43 | 'defaultAction' => 'save' |
||
44 | ], |
||
45 | 'delete' => [ |
||
46 | 'class' => OrganizationController::class, |
||
47 | 'defaultAction' => 'delete' |
||
48 | ] |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * @inheritdoc |
||
53 | */ |
||
54 | public function init() |
||
55 | { |
||
56 | |||
57 | // Do parent |
||
58 | parent::init(); |
||
59 | |||
60 | // Register our fields |
||
61 | Event::on( |
||
62 | Fields::class, |
||
63 | Fields::EVENT_REGISTER_FIELD_TYPES, |
||
64 | function (RegisterComponentTypesEvent $event) { |
||
65 | $event->types[] = OrganizationField::class; |
||
66 | $event->types[] = UserField::class; |
||
67 | } |
||
68 | ); |
||
69 | |||
70 | // Register our elements |
||
71 | Event::on( |
||
72 | Elements::class, |
||
73 | Elements::EVENT_REGISTER_ELEMENT_TYPES, |
||
74 | function (RegisterComponentTypesEvent $event) { |
||
75 | $event->types[] = OrganizationElement::class; |
||
76 | } |
||
77 | ); |
||
78 | |||
79 | // Register our CP routes |
||
80 | Event::on( |
||
81 | UrlManager::class, |
||
82 | UrlManager::EVENT_REGISTER_CP_URL_RULES, |
||
83 | [self::class, 'onRegisterCpUrlRules'] |
||
84 | ); |
||
85 | |||
86 | // Twig variables |
||
87 | Event::on( |
||
88 | CraftVariable::class, |
||
89 | CraftVariable::EVENT_INIT, |
||
90 | function (Event $event) { |
||
91 | /** @var CraftVariable $variable */ |
||
92 | $variable = $event->sender; |
||
93 | $variable->set('organization', OrganizationVariable::class); |
||
94 | } |
||
95 | ); |
||
96 | } |
||
97 | |||
98 | |||
99 | /******************************************* |
||
100 | * EVENTS |
||
101 | *******************************************/ |
||
102 | |||
103 | /** |
||
104 | * @param RegisterUrlRulesEvent $event |
||
105 | */ |
||
106 | public static function onRegisterCpUrlRules(RegisterUrlRulesEvent $event) |
||
107 | { |
||
108 | |||
109 | $event->rules = array_merge( |
||
110 | $event->rules, |
||
111 | [ |
||
112 | // SETTINGS |
||
113 | 'organization/configuration' => 'organization/configuration/view/general/index', |
||
114 | 'organization/configuration/layout' => 'organization/configuration/view/layout/index', |
||
115 | 'organization/configuration/type' => 'organization/configuration/view/type/index', |
||
116 | 'organization/configuration/type/new' => 'organization/configuration/view/type/upsert', |
||
117 | 'organization/configuration/type/<typeIdentifier:\d+>' => 'organization/configuration/view/type/upsert', |
||
118 | |||
119 | // ORGANIZATION |
||
120 | 'organization' => 'organization/view/organization/index', |
||
121 | 'organization/new/<typeIdentifier:{handle}>' => 'organization/view/organization/upsert', |
||
122 | 'organization/new' => 'organization/view/organization/upsert', |
||
123 | 'organization/<identifier:\d+>' => 'organization/view/organization/upsert', |
||
124 | 'organization/<identifier:\d+>/<typeIdentifier:{handle}>' => 'organization/view/organization/upsert' |
||
125 | |||
126 | ] |
||
127 | ); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @inheritdoc |
||
132 | * |
||
133 | * @return OrganizationSettings |
||
134 | */ |
||
135 | public function getSettings() |
||
139 | |||
140 | /** |
||
141 | * @return OrganizationSettings |
||
142 | */ |
||
143 | protected function createSettingsModel() |
||
147 | |||
148 | /** |
||
149 | * @inheritdoc |
||
150 | */ |
||
151 | public function getSettingsResponse() |
||
160 | |||
161 | /** |
||
162 | * Delete any existing field layouts, and create default settings |
||
163 | */ |
||
164 | public function afterInstall() |
||
193 | |||
194 | /** |
||
195 | * Remove all field layouts |
||
196 | */ |
||
197 | public function afterUninstall() |
||
209 | |||
210 | /******************************************* |
||
211 | * MODULES |
||
212 | *******************************************/ |
||
213 | /** |
||
214 | * @return modules\configuration\Module |
||
215 | */ |
||
216 | public function getConfiguration() |
||
220 | |||
221 | |||
222 | /******************************************* |
||
223 | * SERVICES |
||
224 | *******************************************/ |
||
225 | |||
226 | /** |
||
227 | * @return services\Field |
||
228 | */ |
||
229 | public function getField() |
||
233 | |||
234 | /** |
||
235 | * @return services\Organization |
||
236 | */ |
||
237 | public function getOrganization() |
||
241 | |||
242 | /** |
||
243 | * @return services\Permission |
||
244 | */ |
||
245 | public function getPermission() |
||
249 | |||
250 | /** |
||
251 | * @return services\Type |
||
252 | */ |
||
253 | public function getType() |
||
257 | |||
258 | /** |
||
259 | * @return services\User |
||
260 | */ |
||
261 | public function getUser() |
||
265 | } |
||
266 |