This repository was archived by the owner on Nov 14, 2022. It is now read-only.
forked from nfourtythree/amnav
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAmNavPlugin.php
More file actions
186 lines (168 loc) · 5.52 KB
/
Copy pathAmNavPlugin.php
File metadata and controls
186 lines (168 loc) · 5.52 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<?php
/**
* Navigation for Craft.
*
* @package Am Nav
* @author Hubert Prein
*/
namespace Craft;
class AmNavPlugin extends BasePlugin
{
public function getName()
{
$settings = $this->getSettings();
if ($settings->pluginName) {
return $settings->pluginName;
}
return Craft::t('a&m nav');
}
public function getReleaseFeedUrl()
{
return 'https://raw.githubusercontent.com/am-impact/amnav/master/releases.json';
}
public function getVersion()
{
return '1.8.0';
}
public function getSchemaVersion()
{
return '1.7.4';
}
public function getDeveloper()
{
return 'a&m impact';
}
public function getDeveloperUrl()
{
return 'http://www.am-impact.nl';
}
public function getSettingsHtml()
{
return craft()->templates->render('amnav/settings', array(
'settings' => $this->getSettings()
));
}
/**
* Plugin has control panel section.
*
* @return boolean
*/
public function hasCpSection()
{
return true;
}
/**
* Plugin has Control Panel routes.
*
* @return array
*/
public function registerCpRoutes()
{
return array(
'amnav' => array(
'action' => 'amNav/navIndex'
),
'amnav/new' => array(
'action' => 'amNav/editNavigation'
),
'amnav/edit/(?P<navId>\d+)' => array(
'action' => 'amNav/editNavigation'
),
'amnav/build/(?P<navId>\d+)' => array(
'action' => 'amNav/buildNavigation'
),
'amnav/build/(?P<navId>\d+)/(?P<locale>{handle})' => array(
'action' => 'amNav/buildNavigation'
)
);
}
/**
* Load a&m nav.
*/
public function init()
{
if (! craft()->isConsole())
{
// Update nodes in a navigation if an Entry was saved
craft()->on('entries.beforeSaveEntry', function(Event $event) {
if (! $event->params['isNewEntry']) {
craft()->amNav_node->updateNodesForElement($event->params['entry'], ElementType::Entry);
}
});
// Delete nodes from a navigation if an Entry was deleted
craft()->on('entries.deleteEntry', function(Event $event) {
craft()->amNav_node->deleteNodesForElement($event->params['entry'], ElementType::Entry);
});
// Update nodes in a navigation if a Category was saved
craft()->on('categories.beforeSaveCategory', function(Event $event) {
if (! $event->params['isNewCategory']) {
craft()->amNav_node->updateNodesForElement($event->params['category'], ElementType::Category);
}
});
// Delete nodes from a navigation if a Category was deleted
craft()->on('categories.deleteCategory', function(Event $event) {
craft()->amNav_node->deleteNodesForElement($event->params['category'], ElementType::Category);
});
// Update nodes in a navigation if an Asset was saved
craft()->on('assets.beforeSaveAsset', function(Event $event) {
if (! $event->params['isNewAsset']) {
craft()->amNav_node->updateNodesForElement($event->params['asset'], ElementType::Asset);
}
});
// Delete nodes from a navigation if an Asset was deleted
craft()->on('assets.deleteAsset', function(Event $event) {
craft()->amNav_node->deleteNodesForElement($event->params['asset'], ElementType::Asset);
});
}
}
/**
* Add commands to a&m command through this hook function.
*
* @return array
*/
public function addCommands() {
$commands = array();
if (craft()->userSession->getUser()->can('accessPlugin-AmNav')) {
$pluginName = $this->getName();
$pluginSettings = $this->getSettings();
$commands[] = array(
'name' => $pluginName . ': ' . Craft::t('Build navigation'),
'more' => true,
'call' => 'getNavigationsByCommand',
'service' => 'amNav',
'vars' => array(
'command' => 'build'
)
);
if (craft()->userSession->isAdmin() || $pluginSettings->canDoActions) {
$commands[] = array(
'name' => $pluginName . ': ' . Craft::t('New navigation'),
'url' => UrlHelper::getUrl('amnav/new')
);
$commands[] = array(
'name' => $pluginName . ': ' . Craft::t('Navigation settings'),
'more' => true,
'call' => 'getNavigationsByCommand',
'service' => 'amNav',
'vars' => array(
'command' => 'settings'
)
);
}
}
return $commands;
}
/**
* Plugin settings.
*
* @return array
*/
protected function defineSettings()
{
return array(
'pluginName' => array(AttributeType::String),
'canDoActions' => array(AttributeType::Bool, 'default' => false),
'quietErrors' => array(AttributeType::Bool, 'default' => false)
);
}
}