function display_cache_field_attach_view_alter in Display Cache 7
Implements hook_field_attach_view_alter().
File
- ./
display_cache.module, line 324 - Module file for Display Cache.
Code
function display_cache_field_attach_view_alter(&$output, $context) {
// Disable display_cache by global setting.
if (variable_get('display_cache_disable', FALSE) === TRUE) {
return;
}
$entity_type = $context['entity_type'];
$entity_id = entity_id($entity_type, $context['entity']);
$view_mode = $context['view_mode'];
// Get bundle.
if (isset($output['#bundle'])) {
$bundle = $output['#bundle'];
}
else {
$first_field = reset($output);
$bundle = $first_field['#bundle'];
}
$settings = display_cache_get_settings($entity_type, $bundle, $view_mode);
// Cache if enabled.
if (!empty($settings['default']['use']) && $settings['default']['use'] == DISPLAY_CACHE_FIELDS) {
foreach (element_children($output) as $field_name) {
if (array_key_exists($field_name, $settings) && $settings[$field_name]['override'] != DISPLAY_CACHE_DISABLED) {
$element =& $output[$field_name];
$keys = display_cache_get_cache_keys($entity_type, $entity_id, $view_mode, $field_name);
$element['#cache'] = array(
'keys' => $keys,
'bin' => DISPLAY_CACHE_CACHE_BIN,
'granularity' => $settings[$field_name]['granularity'],
);
}
}
}
}