Commit f175e698 authored by Dries's avatar Dries

- Patch #597832 by markus_petruxm: add (), arguments to field_access() to...

- Patch #597832 by markus_petruxm: add (),  arguments to field_access() to enhance the context for hook_field_access().
parent 0ca8f9b2
......@@ -1433,11 +1433,15 @@ function hook_field_build_modes($obj_type) {
* - "view"
* @param $field
* The field on which the operation is to be performed.
* @param $obj_type
* The type of $object; e.g. 'node' or 'user'.
* @param $object
* (optional) The object for the operation.
* @param $account
* (optional) The account to check, if not given use currently logged in user.
* @return
* TRUE if the operation is allowed;
* FALSE if the operation is denied.
*/
function hook_field_access($op, $field, $account) {
function hook_field_access($op, $field, $obj_type, $object, $account) {
}
......@@ -84,7 +84,7 @@ function field_default_view($obj_type, $object, $field, $instance, $langcode, $i
'#theme' => 'field',
'#weight' => $display['weight'],
'#title' => check_plain(t($instance['label'])),
'#access' => field_access('view', $field),
'#access' => field_access('view', $field, $obj_type, $object),
'#label_display' => $label_display,
'#build_mode' => $build_mode,
'#language' => $langcode,
......
......@@ -22,7 +22,7 @@ function field_default_form($obj_type, $object, $field, $instance, $langcode, $i
// If the field is not accessible, don't add anything. The field value will
// be left unchanged on update, or considered empty on insert (default value
// will be inserted if applicable).
if (!field_access('edit', $field)) {
if (!field_access('edit', $field, $obj_type, $object)) {
return $addition;
}
......
......@@ -499,7 +499,7 @@ function field_format($obj_type, $object, $field, $item, $formatter_type = NULL,
$field = field_info_field($field);
}
if (field_access('view', $field)) {
if (field_access('view', $field, $obj_type, $object)) {
$field_type = field_info_field_types($field['type']);
// We need $field, $instance, $obj_type, $object to be able to display a value...
......@@ -624,20 +624,24 @@ function field_has_data($field) {
* - "view"
* @param $field
* The field on which the operation is to be performed.
* @param $obj_type
* The type of $object; e.g. 'node' or 'user'.
* @param $object
* (optional) The object for the operation.
* @param $account
* (optional) The account to check, if not given use currently logged in user.
* @return
* TRUE if the operation is allowed;
* FALSE if the operation is denied.
*/
function field_access($op, $field, $account = NULL) {
function field_access($op, $field, $obj_type, $object = NULL, $account = NULL) {
global $user;
if (is_null($account)) {
$account = $user;
}
$field_access = module_invoke_all('field_access', $op, $field, $account);
$field_access = module_invoke_all('field_access', $op, $field, $obj_type, $object, $account);
foreach ($field_access as $value) {
if ($value === FALSE) {
return FALSE;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment