/[drupal]/contributions/modules/taxonomy_role/taxonomy_role.module
ViewVC logotype

Contents of /contributions/modules/taxonomy_role/taxonomy_role.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.4 - (show annotations) (download) (as text)
Sun Jul 6 16:42:40 2008 UTC (16 months, 3 weeks ago) by der
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-BETA1, HEAD
Changes since 1.3: +10 -11 lines
File MIME type: text/x-php
initial 6 commit
1 <?php
2 // $Id:
3
4 /**
5 * @file
6 * Taxonomy role - allows restriction of access to vocabularies
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function taxonomy_role_help($path, $arg) {
13 switch ($path) {
14 case 'admin/help#taxonomy_role':
15 $output = '<p>'. t('This module allows you to restrict access to vocabularies on node forms by role. Once it is installed, you will need to configure the permissions for new and existing vocabularies.'). '</p>';
16 return $output;
17 }
18 }
19
20 /**
21 * Implementation of hook_menu().
22 */
23 function taxonomy_role_menu() {
24 $items = array();
25
26 $items['admin/settings/taxonomy_role'] = array(
27 'title' => t('Taxonomy Role'),
28 'page callback' => 'drupal_get_form',
29 'page arguments' => array('taxonomy_role_admin_settings_form'),
30 'access arguments' => array('administer site configuration'),
31 'description' => t('Configure Taxonomy Role settings.'),
32 'type' => MENU_NORMAL_ITEM,
33 );
34
35 return $items;
36 }
37
38 /**
39 * Implementation of hook_form_alter().
40 */
41 function taxonomy_role_form_alter(&$form, &$form_state, $form_id) {
42 if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id) {
43 if (isset($form['taxonomy'])) {
44 $vocabularies = taxonomy_get_vocabularies();
45 foreach ($form['taxonomy'] as $vid => $value) {
46 if (is_numeric($vid) && !user_access('access '. check_plain($vocabularies[$vid]->name) .' vocabulary')) {
47 if (variable_get('taxonomy_role_'. $vid, 'hidden') == 'hidden') {
48 $form['taxonomy'][$vid] = array(
49 '#type' => 'value',
50 '#value' => $form['taxonomy'][$vid]['#default_value'],
51 );
52 }
53 else {
54 $form['taxonomy'][$vid]['#disabled'] = TRUE;
55 }
56 }
57 }
58 if (isset($form['taxonomy']['tags'])) {
59 foreach ($form['taxonomy']['tags'] as $vid => $value) {
60 if (is_numeric($vid) && !user_access('access '. check_plain($vocabularies[$vid]->name) .' vocabulary')) {
61 if (variable_get('taxonomy_role_'. $vid, 'hidden') == 'hidden') {
62 $form['taxonomy']['tags'][$vid] = array(
63 '#type' => 'value',
64 '#value' => $form['taxonomy']['tags'][$vid]['#default_value'],
65 );
66 }
67 else {
68 $form['taxonomy']['tags'][$vid]['#disabled'] = TRUE;
69 }
70 }
71 }
72 }
73 }
74 }
75 }
76
77 /**
78 * Implementation of hook_perm().
79 */
80 function taxonomy_role_perm() {
81 $vocabularies = taxonomy_get_vocabularies();
82 $perms = array();
83 foreach ($vocabularies as $vocabulary) {
84 $perms[] = 'access '. check_plain($vocabulary->name) .' vocabulary';
85 }
86 return $perms;
87 }
88
89 /**
90 * Administration page callback.
91 */
92 function taxonomy_role_admin_settings_form() {
93 $vocabularies = taxonomy_get_vocabularies();
94 if (count($vocabularies)) {
95 $form['settings'] = array(
96 '#type' => 'fieldset',
97 '#collapsible' => FALSE,
98 '#title' => t('Vocabulary visibility'),
99 '#description' => t("When a user is denied access to a vocabulary, you can decide whether that vocabulary's field will be hidden or disabled. The latter allows users to see the terms."),
100 );
101 $options = array(
102 'hidden' => t('Hidden'),
103 'disabled' => t('Disabled'),
104 );
105 foreach ($vocabularies as $vid => $vocabulary) {
106 $form['settings']['taxonomy_role_'. $vid] = array(
107 '#type' => 'select',
108 '#title' => check_plain($vocabulary->name),
109 '#multiple' => FALSE,
110 '#required' => FALSE,
111 '#options' => $options,
112 '#default_value' => variable_get('taxonomy_role_'. $vid, 'hidden'),
113 );
114 }
115 }
116 return system_settings_form($form);
117 }
118

  ViewVC Help
Powered by ViewVC 1.1.2