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

Diff of /contributions/modules/field_permissions/includes/field_access.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     * Implementation of helper functions related to hook_field_access().
7     */
8    
9    /**
10     * Implementation of hook_field_access('view').
11     */
12    function _field_permissions_field_view_access($field_name, $field_permissions, $account, $node) {
13      // Check if user has access to view this field in any node.
14      if (!empty($field_permissions['view']) && user_access('view '. $field_name, $account)) {
15        return TRUE;
16      }
17    
18      // If 'view own' permission has been enabled for this field, then we can
19      // check if the user has the right permission, and ownership of the node.
20      if (!empty($field_permissions['view own']) && user_access('view own '. $field_name, $account)) {
21    
22        // When content_access('view') is invoked, it may or may not provide a
23        // node object. It will, almost always, except when this function is
24        // invoked as a field access callback from Views, where it is used to
25        // evaluate if the field can be included in the query itself. In this
26        // case we should grant access. Views will invoke content_access('view')
27        // again, indirectly, when rendering the fields using content_format(),
28        // and this time it will provide a pseudo node object that includes the
29        // uid of the node author, so here is where we have the chance to
30        // evaluate ownership to check for 'view own <field>' permission.
31        return (!isset($node) || $node->uid == $account->uid);
32      }
33    
34      return FALSE;
35    }
36    
37    /**
38     * Implementation of hook_field_access('edit').
39     */
40    function _field_permissions_field_edit_access($field_name, $field_permissions, $account, $node) {
41      // Check if user has access to edit this field on node creation.
42      if (empty($node->nid) && !empty($field_permissions['create'])) {
43        return user_access('create '. $field_name, $account);
44      }
45    
46      // Check if user has access to edit this field in any node.
47      if (!empty($field_permissions['edit']) && user_access('edit '. $field_name, $account)) {
48        return TRUE;
49      }
50    
51      // If 'edit own' permission has been enabled for this field, then we can
52      // check if the user has the right permission, and ownership of the node.
53      if (!empty($field_permissions['edit own']) && user_access('edit own '. $field_name, $account) && $node->uid == $account->uid) {
54        return TRUE;
55      }
56    
57      return FALSE;
58    }

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

  ViewVC Help
Powered by ViewVC 1.1.2