root / drupal7 / sites / all / modules / field_permissions / field_permissions.api.php @ 651307cd
1 | 08475715 | Assos Assos | <?php
|
---|---|---|---|
2 | |||
3 | /**
|
||
4 | * @file
|
||
5 | * Hooks provided by the Field Permission module.
|
||
6 | */
|
||
7 | |||
8 | /**
|
||
9 | * Defines the owner of an entity.
|
||
10 | *
|
||
11 | * Because not all entities have uids, this hook allows other modules to specify
|
||
12 | * one.
|
||
13 | *
|
||
14 | * @param int $uid
|
||
15 | * The userid that will be checked against the current user's account->uid.
|
||
16 | * @param object $entity
|
||
17 | * The entity this field belongs to.
|
||
18 | */
|
||
19 | // @codingStandardsIgnoreStart
|
||
20 | function hook_field_permissions_userid_ENTITY_TYPE_alter(&$uid, $entity) { |
||
21 | // This example always assigns user 15 as the owner of an entity.
|
||
22 | $uid = 15; |
||
23 | } |
||
24 | // @codingStandardsIgnoreEnd
|
||
25 | |||
26 | /**
|
||
27 | * Alter the permissions handled by field_permissions module.
|
||
28 | *
|
||
29 | * @param array $permissions
|
||
30 | * The $permissions array created by the Field permissions module.
|
||
31 | * @param string $field_label
|
||
32 | * The field name.
|
||
33 | */
|
||
34 | function hook_field_permissions_list_alter(&$permissions, $field_label) { |
||
35 | $permissions += array( |
||
36 | 'view own node preview' => array( |
||
37 | 'label' => t('View own field on node preview'), |
||
38 | 'title' => t('View own value for field %field on node preview', array('%field' => $field_label)), |
||
39 | ), |
||
40 | 'view node preview' => array( |
||
41 | 'label' => t('View field on node preview'), |
||
42 | 'title' => t("View anyone's value for field %field on node preview", array('%field' => $field_label)), |
||
43 | ), |
||
44 | ); |
||
45 | } |
||
46 | |||
47 | /**
|
||
48 | * Hook invoked with custom field permissions.
|
||
49 | *
|
||
50 | * This hook can be used to revoke access to the field. If access is not
|
||
51 | * revoked, default access of the Field permissions module will apply.
|
||
52 | *
|
||
53 | * @param string $op
|
||
54 | * The operation to be performed. Possible values: 'edit', 'view'.
|
||
55 | * @param array $field
|
||
56 | * The field on which the operation is to be performed.
|
||
57 | * @param string $entity_type
|
||
58 | * The type of $entity; for example, 'node' or 'user'.
|
||
59 | * @param object $entity
|
||
60 | * (optional) The entity for the operation.
|
||
61 | * @param object $account
|
||
62 | * (optional) The account to check; if not given use currently logged in user.
|
||
63 | *
|
||
64 | * @return bool
|
||
65 | * FALSE if the operation is not allowed.
|
||
66 | *
|
||
67 | * @see field_permissions_field_access()
|
||
68 | * @see field_access()
|
||
69 | */
|
||
70 | function hook_field_permissions_custom_field_access($op, $field, $entity_type, $entity, $account) { |
||
71 | if ($op == 'view' && $entity_type == 'node' && !empty($entity)) { |
||
72 | // Check if user has access to view this field in any entity.
|
||
73 | if (!user_access('view node preview ' . $field['field_name'], $account)) { |
||
74 | return FALSE; |
||
75 | } |
||
76 | |||
77 | // If the user has permission to view entities that they own, return TRUE if
|
||
78 | // they own this entity or FALSE if they don't.
|
||
79 | if (user_access('view own node preview ' . $field['field_name'], $account)) { |
||
80 | return _field_permissions_entity_is_owned_by_account($entity, $account); |
||
81 | } |
||
82 | } |
||
83 | |||
84 | return TRUE; |
||
85 | } |