/[drupal]/contributions/modules/field_permissions/includes/admin.inc
ViewVC logotype

Diff of /contributions/modules/field_permissions/includes/admin.inc

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

revision 1.1, Sat Nov 7 21:49:41 2009 UTC revision 1.1.2.1, Sat Nov 7 21:49:41 2009 UTC
# Line 0  Line 1 
1    <?php
2    // $Id$
3    
4    /**
5     * @file
6     * Administrative interface for the Field Permissions module.
7     */
8    
9    /**
10     * Obtain the list of field permissions.
11     */
12    function field_permissions_list($field_label = '') {
13      return array(
14        'create'   => t('Create @field (edit on node creation).', array('@field' => $field_label)),
15        'edit'     => t('Edit @field, regardless of node author.', array('@field' => $field_label)),
16        'edit own' => t('Edit own @field on node created by the user.', array('@field' => $field_label)),
17        'view'     => t('View @field, regardless of node author.', array('@field' => $field_label)),
18        'view own' => t('View own @field on node created by the user.', array('@field' => $field_label)),
19      );
20    }
21    
22    /**
23     * Implementation of hook_perm().
24     */
25    function _field_permissions_perm() {
26      $perms = array();
27      foreach (content_fields() as $field_name => $field) {
28        if (!empty($field['field_permissions'])) {
29          foreach (array_keys(field_permissions_list()) as $permission_type) {
30            if (!empty($field['field_permissions'][$permission_type])) {
31              $perms[] = $permission_type .' '. $field_name;
32            }
33          }
34        }
35      }
36      return $perms;
37    }
38    
39    /**
40     * Implementation of hook_field_settings_alter().
41     */
42    function _field_permissions_field_settings_alter(&$settings, $op, $field) {
43      switch ($op) {
44        case 'form':
45          $field_permissions = array();
46          foreach (field_permissions_list($field['widget']['label']) as $permission_type => $description) {
47            $field_permissions[$permission_type] = $description;
48          }
49          $settings['field_permissions'] = array(
50            '#title' => t('Field permissions'),
51            '#type' => 'checkboxes',
52            '#checkall' => TRUE,
53            '#options' => $field_permissions,
54            '#default_value' => (isset($field['field_permissions']) && is_array($field['field_permissions']) ? $field['field_permissions'] : array()),
55            '#description' => t('Use these options to enable role based permissions for this field.
56    When permissions are enabled, access to this field is denied by default and explicit permissions should be granted to the proper user roles from the <a href="@admin-permissions">permissions administration</a> page.
57    On the other hand, when these options are disabled, field permissions are inherited from node view and/or edit permissions. In example, users allowed to view a particular node will also be able to view this field, and so on.', array(
58              '@admin-permissions' => url('admin/user/permissions'),
59            )),
60            '#weight' => -1,
61          );
62          break;
63    
64        case 'save':
65          $settings[] = 'field_permissions';
66          break;
67      }
68    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.1.2.1

  ViewVC Help
Powered by ViewVC 1.1.2