/
Plugin.php
105 lines (93 loc) · 2.94 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
104
105
<?php namespace VojtaSvoboda\LocationTown;
use Backend;
use Event;
use RainLab\Location\Models\State;
use System\Classes\PluginBase;
use VojtaSvoboda\LocationTown\Models\Town;
/**
* LocationTown Plugin Information File
*/
class Plugin extends PluginBase
{
/** @var array $require Required plugins */
public $require = [
'RainLab.Location'
];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'vojtasvoboda.locationtown::lang.plugin.name',
'description' => 'vojtasvoboda.locationtown::lang.plugin.description',
'author' => 'Vojta Svoboda',
'icon' => 'icon-building-o',
];
}
public function registerComponents()
{
return [
'VojtaSvoboda\LocationTown\Components\Town' => 'locationTown',
'VojtaSvoboda\LocationTown\Components\Towns' => 'locationTowns',
];
}
public function registerSettings()
{
return [
'locationtown' => [
'label' => 'vojtasvoboda.locationtown::lang.settings.label',
'description' => 'vojtasvoboda.locationtown::lang.settings.description',
'category' => 'rainlab.location::lang.plugin.name',
'icon' => 'icon-building-o',
'url' => Backend::url('vojtasvoboda/locationtown/towns'),
'order' => 500,
'permissions' => ['vojtasvoboda.locationtown.*'],
],
];
}
/**
* Register new Twig variables
* @return array
*/
public function registerMarkupTags()
{
return [
'functions' => [
'form_select_town' => ['VojtaSvoboda\LocationTown\Models\Town', 'formSelect'],
]
];
}
public function boot()
{
$this->app->bind('locationtowns', 'VojtaSvoboda\LocationTown\Models\Town');
State::extend(function($model) {
$model->hasMany['towns'] = 'VojtaSvoboda\LocationTown\Models\Town';
});
$this->initMenuItems();
}
/**
* Register new MenuItems, which is usefull for Sitemap and etc.
*/
public function initMenuItems()
{
Event::listen('pages.menuitem.listTypes', function() {
return [
'location-town' => 'Location Town',
'all-location-towns' => 'All location towns'
];
});
Event::listen('pages.menuitem.getTypeInfo', function($type) {
if ($type == 'location-town' || $type == 'all-location-towns') {
return Town::getMenuTypeInfo($type);
}
});
Event::listen('pages.menuitem.resolveItem', function($type, $item, $url, $theme) {
if ($type == 'location-town' || $type == 'all-location-towns') {
return Town::resolveMenuItem($item, $url, $theme);
}
});
}
}