function multifield_field_access in Multifield 7.2
Same name and namespace in other branches
- 7 multifield.field.inc \multifield_field_access()
Implements hook_field_access().
@todo Investigate improving performance of this function.
File
- ./
multifield.field.inc, line 142 - Field integration for the Multifield module.
Code
function multifield_field_access($op, $field, $entity_type, $entity, $account) {
// We should return FALSE if all the subfields' field_access() checks all
// return FALSE.
if ($machine_name = multifield_extract_multifield_machine_name($field)) {
$subfield_names = multifield_type_get_subfields($machine_name);
$subfield_access = array();
if (!empty($entity) && ($items = field_get_items($entity_type, $entity, $field['field_name']))) {
foreach ($items as $delta => $item) {
$pseudo_entity = _multifield_field_item_to_entity($machine_name, $item);
foreach ($subfield_names as $subfield_name) {
$subfield = field_info_field($subfield_name);
$subfield_access[$subfield_name . ':' . $delta] = field_access($op, $subfield, 'multifield', $pseudo_entity, $account);
}
}
}
else {
foreach ($subfield_names as $subfield_name) {
$subfield = field_info_field($subfield_name);
$subfield_access[$subfield_name] = field_access($op, $subfield, 'multifield', NULL, $account);
}
}
// If all of the subfields returned FALSE, then this should return FALSE.
if (!array_filter($subfield_access)) {
return FALSE;
}
}
}