-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathAdminbarPlugin.php
More file actions
102 lines (92 loc) · 2.5 KB
/
Copy pathAdminbarPlugin.php
File metadata and controls
102 lines (92 loc) · 2.5 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
<?php
namespace Craft;
class AdminbarPlugin extends BasePlugin
{
//private $_settings;
public function getName()
{
return Craft::t('Admin Bar');
}
public function getVersion()
{
return '2.1.2';
}
public function getSchemaVersion()
{
return '2.0.0';
}
public function getDescription()
{
return 'Front-end shortcuts for users logged into Craft CMS.';
}
public function getDeveloper()
{
return 'Will Browar';
}
public function getDeveloperUrl()
{
return 'http://wbrowar.com';
}
public function getDocumentationUrl()
{
return 'https://github.com/wbrowar/adminbar';
}
public function getReleaseFeedUrl()
{
return 'https://raw.githubusercontent.com/wbrowar/adminbar/master/releases.json';
}
public function hasCpSection()
{
return false;
}
public function init()
{
craft()->templates->hook('renderAdminBar', function() {
$adminbar = craft()->plugins->getPlugin('Adminbar');
if (craft()->adminbar->canEmbed()) {
$config = array (
'color' => $adminbar->getSettings()->defaultColor,
'sticky' => true,
'type' => 'primary',
'useCss' => true,
'useJs' => true,
);
// get current page element
$element = craft()->urlManager->getMatchedElement();
if (!empty($element)) {
if ($element->getElementType() === ElementType::Entry) {
$config['entry'] = $element;
} elseif ($element->getElementType() === ElementType::Category) {
$config['category'] = $element;
}
}
// show admin bar in template
craft()->adminbar->bar($config);
}
});
}
protected function defineSettings()
{
return array(
'autoEmbed' => array(AttributeType::Bool, 'default' => false),
'customLinks' => array(AttributeType::Mixed, 'default' => array()),
'defaultColor' => array(AttributeType::String, 'default' => '#d85b4b'),
);
}
public function getSettingsHtml()
{
// clear admin bar cache
craft()->adminbar->clearAdminBarCache();
// output settings template
return craft()->templates->render('adminbar/settings', array(
'settings' => $this->getSettings(),
));
}
public function prepSettings($settings) {
// if last custom link is deleted, replace old settings with blank array
if (!isset($settings['customLinks'])) {
$settings['customLinks'] = array();
}
return $settings;
}
}