'admin/settings/cck_field_perms', 'title' => t('CCK Field Permisions'), 'callback' => 'cck_field_perms_form', 'access' => user_access('administer cck field permisions'), 'type' => MENU_NORMAL_ITEM, ); } return $items; } /** * Impementation of hook perms */ function cck_field_perms_perm(){ $field_prems = unserialize(variable_get('cfp_values', null)); if ($field_prems) { foreach($field_prems as $type_name => $fields){ foreach($fields as $field_name){ foreach (cck_field_perms_verbs() as $verb){ $perm_list[] = "$type_name $field_name $verb"; } } } } return $perm_list; } /** * helper function to unset form values * * @form is drupal form * @verb is create or update * @return is the modified drupal form * */ function _cfp_form_helper($form_id, $form, $verb){ //content_video_node_form $types = variable_get('cfp_types', null); if ($types){ foreach ($types as $type){ if($form_id == $type . "_node_form"){ $disallowed_fields = unserialize(variable_get('cfp_values', null)); foreach ($disallowed_fields[$type] as $disallowed_field){ if (!(user_access("$type $disallowed_field $verb"))){ unset($form[$disallowed_field]); } } } } } return $form; } /** * Implemenation of hook form_alter */ function cck_field_perms_form_alter($form_id, &$form){ // detect if we're editing or creating if ((arg(0) == "node") && (arg(2) == "edit")){ $verb = "update"; } else { $verb = "create"; } $form = _cfp_form_helper($form_id, $form, $verb); } /** * creates the admin form */ function cck_field_perms_form(){ $form['field_perms'] = array( '#type' => 'fieldset', '#title' => t('Enable field permissions on content types.'), '#description' => t("This module allows an admin to restrict CCK fields to some roles." . "Once you have enabled a content type, select which fields you'd like to restrict." . "Then, go to " . l("admin/access", "admin/access"). " to allow user roles acces to that field."), ); $types = content_types(); foreach ($types as $key => $value){ $options[$key] = $key; } $enabled_types = variable_get('cfp_types', null); $form['field_perms']['cfp_types'] = array( '#type' => 'checkboxes', '#title' => t('Content types'), '#description' => t('Select content types you wish to enable permisions on.'), '#options' => $options, '#default_value' => $enabled_types, ); $the_settings = unserialize(variable_get('cfp_values', '')); if($enabled_types){ foreach ($enabled_types as $enabled_type){ if ($enabled_type != '0'){ $form['field_fields'][$enabled_type] = array( '#type' => 'fieldset', '#title' => "$enabled_type fields", ); foreach ($types[$enabled_type]['fields'] as $field){ $field_prems[$field['field_name']] = $field['field_name']; } $form['field_fields'][$enabled_type]["{$enabled_type}_fields"]= array( '#type' => 'checkboxes', '#title' => t('Field permisions'), '#description' => t('Select fields you wish to enable permissions on.'), '#options' => $field_prems, '#default_value' => $the_settings[$enabled_type], '#description' => t("Each field that is checked will have permissions enabled on it."), ); } } } $form['submit'] = array( '#type' => 'submit', '#value' => t('Save') ); $output = drupal_get_form('cck_field_perms_form', $form); return $output; } function cck_field_perms_form_submit($form_id, $form_values){ variable_set('cfp_types', $form_values['cfp_types']); foreach($form_values as $key => $value){ if(strstr($key, "_fields")){ foreach ($value as $field){ if ($field != '0'){ $name = substr($key, 0,strpos($key, '_fields')); $stored_values[$name][$field] = $field; } } } } variable_set('cfp_values', serialize($stored_values)); drupal_set_message("Remember to update ". l("admin/access", "admin/access") ." after you've changed permissions."); }