function authcache_field_field_attach_view_alter in Authenticated User Page Caching (Authcache) 7.2
Implements hook_field_attach_view_alter().
File
- modules/
authcache_field/ authcache_field.module, line 85 - Authcache support for fields.
Code
function authcache_field_field_attach_view_alter(&$output, $context) {
if (authcache_p13n_is_authcache_p13n_request()) {
return;
}
$entity_type = $context['entity_type'];
$entity = $context['entity'];
list($entity_id, $fixme_revision_support, $bundle_name) = entity_extract_ids($entity_type, $entity);
unset($fixme_revision_support);
$view_mode = $context['view_mode'];
foreach (element_children($output) as $field_name) {
$instance = field_info_instance($entity_type, $field_name, $bundle_name);
if (!empty($instance['settings']['authcache']['status'])) {
if ($view_mode === '_custom') {
// Invoked from within field_view_field with a _custom display. Cannot
// handle this atm.
authcache_cancel(t('FIXME: authcache_field - what should we do with custom view_modes?'));
}
else {
// The language key is only set when the alter hook was invoked from
// within field_attach_view and never when invoked from within
// field_view_field.
$language = $context['language'];
$config = $instance['settings']['authcache'];
$config += authcache_p13n_config_defaults();
$assembly_id = "field/{$entity_type}/{$field_name}";
$param = array(
$entity_id,
$view_mode,
$language,
);
authcache_p13n_attach($output[$field_name], array(
'#theme' => 'authcache_p13n_partial',
'#assembly' => $assembly_id,
'#partial' => 'field',
'#param' => implode(':', $param),
'#clients' => $config['clients'],
'#fallback' => $config['fallback'],
));
}
}
}
}