by joachim: Fixed missing UI confirmation message on saving permissions.
[project/permission_grid.git] / permission_grid.permissions.inc
1 <?php
2 /**
3 * @file permission_grid.permissions.inc
4 * Contains hook implementations on behalf of other modules.
5 */
6
7 // =========================================================== Core modules
8
9 /**
10 * Implements hook_permission_grid_info() on behalf of node module.
11 */
12 function node_permission_grid_info() {
13 $return = array(
14 'node' => array(
15 'label' => t('Content type'),
16 'objects' => array(),
17 'verb_groups' => array(
18 'core' => array(
19 'pattern' => '%verb %object content',
20 'verbs' => array(
21 'create' => t('Create'),
22 'edit own' => t('Edit own'),
23 'edit any' => t('Edit any'),
24 'delete own' => t('Delete own'),
25 'delete any' => t('Delete any'),
26 ),
27 ),
28 ),
29 ),
30 );
31
32 $node_types = node_type_get_types();
33 $configured_types = node_permissions_get_configured_types();
34 foreach ($configured_types as $type) {
35 $return['node']['objects'][$type] = $node_types[$type]->name;
36 }
37
38 return $return;
39 }
40
41 /**
42 * Implements hook_permission_grid_info() on behalf of taxonomy module.
43 */
44 function taxonomy_permission_grid_info() {
45 $vocabularies = taxonomy_get_vocabularies();
46 $return = array(
47 'vocabulary' => array(
48 'label' => t('Taxonomy'),
49 'objects' => array(),
50 'verb_groups' => array(
51 'core' => array(
52 'pattern' => '%verb terms in %object',
53 'verbs' => array(
54 'edit' => t('Edit terms'),
55 'delete' => t('Delete terms'),
56 ),
57 // Oh yeah, taxonomy module, you're so cool you get a special thing
58 // just for you. And by 'cool' I mean 'still in D6 land'.
59 'object_process_callback' => 'permission_grid_taxonomy_object_process',
60 )
61 ),
62 ),
63 );
64
65 foreach ($vocabularies as $vocabulary) {
66 $return['vocabulary']['objects'][$vocabulary->machine_name] = $vocabulary->name;
67 }
68
69 return $return;
70 }
71
72 /**
73 * Object process callback for taxonomy vocabularies.
74 *
75 * This handles the weirdness with taxonomy permissions using vocabulary ids
76 * rather than machine names.
77 */
78 function permission_grid_taxonomy_object_process($object_name) {
79 $vocabulary_names = taxonomy_vocabulary_get_names();
80 return $vocabulary_names[$object_name]->vid;
81 }
82
83 // =========================================================== Contrib modules
84
85 /**
86 * Implements hook_permission_grid_info_alter() on behalf of vppr module.
87 */
88 function vppr_permission_grid_info_alter(&$info) {
89 $info['vocabulary']['verb_groups']['vppr'] = array(
90 'pattern' => '%verb %object vocabulary terms',
91 'verbs' => array(
92 'administer' => t('Administer terms'),
93 ),
94 );
95 }
96
97 /**
98 * Implements hook_permission_grid_info() on behalf of profile2 module.
99 */
100 function profile2_permission_grid_info() {
101 $return = array(
102 'profile2' => array(
103 'label' => t('Profiles'),
104 'objects' => array(),
105 'verb_groups' => array(
106 'core' => array(
107 'pattern' => '%verb %object profile',
108 'verbs' => array(
109 'edit own' => t('Edit own'),
110 'edit any' => t('Edit any'),
111 'view own' => t('View own'),
112 'view any' => t('View any'),
113 ),
114 ),
115 ),
116 ),
117 );
118
119 foreach (profile2_get_types() as $type => $type_info) {
120 $return['profile2']['objects'][$type] = $type_info->label;
121 }
122
123 return $return;
124 }
125
126 /**
127 * Implements hook_permission_grid_info() on behalf of commerce module.
128 */
129 function commerce_permission_grid_info() {
130 $info = array();
131
132 // @todo: other commerce entity types.
133 foreach (array('commerce_product') as $entity_type) {
134 $entity_info = entity_get_info($entity_type);
135 $types = array();
136 foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
137 $types[$bundle] = $bundle_info['label'];
138 }
139
140 $info[$entity_type] = array(
141 'label' => $entity_info['label'],
142 'objects' => $types,
143 'verb_groups' => array(
144 // Put plural first so 'create' comes first.
145 'commerce_plural' => array(
146 'pattern' => "%verb $entity_type entities of bundle %object",
147 'verbs' => array(
148 'create' => t('Create'),
149 'edit own' => t('Edit own'),
150 'view own' => t('View own'),
151 ),
152 ),
153 'commerce_singular' => array(
154 'pattern' => "%verb $entity_type entity of bundle %object",
155 'verbs' => array(
156 'edit any' => t('Edit any'),
157 'view any' => t('View any'),
158 ),
159 ),
160 ),
161 );
162 }
163 return $info;
164 }
165
166 /**
167 * Implements hook_permission_grid_info() on behalf of flag module.
168 */
169 function flag_permission_grid_info() {
170 $return = array(
171 'flag' => array(
172 'label' => t('Flag'),
173 'objects' => array(),
174 'verb_groups' => array(
175 'flag' => array(
176 'pattern' => '%verb %object',
177 'verbs' => array(
178 'flag' => t('Flag'),
179 'unflag' => t('Unflag'),
180 ),
181 ),
182 ),
183 ),
184 );
185
186 foreach (flag_get_flags() as $flag) {
187 $return['flag']['objects'][$flag->name] = $flag->title;
188 }
189
190 return $return;
191 }