-
Notifications
You must be signed in to change notification settings - Fork 2
/
easy_admin.install
243 lines (222 loc) · 6.96 KB
/
easy_admin.install
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/**
* @file
* Install functions for the easy_admin module
*/
/**
* Implements hook_install().
*/
function easy_admin_install() {
$menuExists = db_select('menu_custom', 'mc')
->fields('mc', array('menu_name'))
->condition('menu_name', 'manager')
->execute()
->fetchField();
if ($menuExists == NULL) {
// Create the client admin menu
$menu = array(
'menu_name' => 'manager',
'title' => 'Manager Menu',
'description' => 'Links for content managers that dont need access to all the developer/admin stuff.'
);
menu_save($menu);
// Add menu items to the new manager menu - Parent Items
$item = array(
'link_path' => '<front>',
'link_title' => 'Home',
'menu_name' => 'manager',
'weight' => -10,
'options' => array('attributes' => array('class' => array('home'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => '<nolink>',
'link_title' => 'Add Content',
'menu_name' => 'manager',
'weight' => -8,
'options' => array('attributes' => array('class' => array('add'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => '<nolink>',
'link_title' => 'Manage Content',
'menu_name' => 'manager',
'weight' => -6,
'options' => array('attributes' => array('class' => array('manage'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => '<nolink>',
'link_title' => 'People',
'menu_name' => 'manager',
'weight' => -4,
'options' => array('attributes' => array('class' => array('users'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
$people_id = menu_link_save($item);
$item = array(
'link_path' => 'admin/structure/menu/manage/main-menu',
'link_title' => 'Manage Menu',
'menu_name' => 'manager',
'weight' => -2,
'options' => array('attributes' => array('class' => array('main_menu'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => '<nolink>',
'link_title' => 'Settings',
'menu_name' => 'manager',
'weight' => 0,
'options' => array('attributes' => array('class' => array('settings'))),
'customized' => 1,
'language' => NULL,
'module' => 'menu',
);
$settings_id = menu_link_save($item);
// Default child elements
$item = array(
'link_path' => 'admin/people/create',
'link_title' => 'Add People',
'menu_name' => 'manager',
'weight' => -2,
'options' => array('attributes' => array('class' => array('add-users'))),
'customized' => 1,
'language' => NULL,
'plid' => $people_id,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => 'admin/people',
'link_title' => 'Manage People',
'menu_name' => 'manager',
'weight' => 0,
'options' => array('attributes' => array('class' => array('users'))),
'customized' => 1,
'language' => NULL,
'plid' => $people_id,
'module' => 'menu',
);
menu_link_save($item);
$item = array(
'link_path' => 'admin/config/search/redirect',
'link_title' => 'URL Redirects',
'menu_name' => 'manager',
'weight' => 0,
'options' => array('attributes' => array('class' => array('redirect'))),
'customized' => 1,
'language' => NULL,
'plid' => $settings_id,
'module' => 'menu',
);
menu_link_save($item);
} // End If !$menuExists
// Check to see if the image style exists before creating it
$styleExists = db_select('image_styles', 'i')
->fields('i', array('name'))
->condition('name', 'square_profile_pic')
->execute();
if ($styleExists == NULL) {
// Create an image style for the users pic
$style = image_style_save(array(
'name' => 'square_profile_pic',
'label' => 'Square - Profile Pic')
);
$effect = array(
'name' => 'image_scale_and_crop',
'data' => array(
'width' => 150,
'height' => 150,
'upscale' => TRUE,
),
'isid' => $style['isid'],
);
image_effect_save($effect);
image_style_flush($style);
} // End If !$styleExists
// Create a profile picture field so we can place it at the top
// of the admin menu
// Check if our field is not already created.
if (!field_info_field('field_profile_picture')) {
// Creates the profile pic directory in the public files folder
$directory = 'public://profile_pic';
file_prepare_directory($directory, FILE_CREATE_DIRECTORY);
//File path in the module
$file_path = drupal_get_path('module', 'easy_admin') . '/assets/img/profile.jpg';
// Save file to new location in public files folder
$file_move = file_unmanaged_copy($file_path, $directory, FILE_EXISTS_RENAME);
//
$file_uri = file_build_uri('profile_pic/profile.jpg');
$file_mime = file_get_mimetype($file_uri);
$file = new stdClass;
$file->uid = 1;
$file->filename = 'profile.jpg';
$file->uri = $file_uri;
$file->filemime = $file_mime;
$file->filesize = filesize($file_uri);
$file->status = 1;
file_save($file);
// Create image field for profile pic usage
$field = array(
'field_name' => 'field_profile_picture',
'type' => 'image',
'settings' => array(
'file_extensions' => 'png jpg jpeg',
'file_directory' => 'profile_pic',
'max_filesize' => '20 MB',
'alt_field' => 1,
'title_field' => 0,
'max_resolution' => '',
'min_resolution' => '200x200',
'default_image' => $file->fid,
'preview_image_style' => 'square_profile_pic',
'user_register_form' => 1,
),
);
field_create_field($field);
// Create the instance on the bundle.
$instance = array(
'field_name' => 'field_profile_picture',
'entity_type' => 'user',
'bundle' => 'user',
'label' => 'Profile Picture',
'description' => 'Profile picture to represent you.',
'required' => TRUE,
'settings' => array(
'file_extensions' => 'png jpg jpeg',
'file_directory' => 'profile_pic',
'max_filesize' => '20 MB',
'alt_field' => 1,
'title_field' => 0,
'max_resolution' => '',
'min_resolution' => '200x200',
'default_image' => $file->fid,
'preview_image_style' => 'square_profile_pic',
'user_register_form' => 1,
),
);
field_create_instance($instance);
}
}
/**
* Implements hook_uninstall().
*/
function easy_admin_uninstall() {
variable_del('easy_admin_roles');
variable_del('easy_admin_show_root');
variable_del('easy_admin_menu');
}