function display_cache_entity_view_alter in Display Cache 7
Implements hook_entity_view_alter().
File
- ./
display_cache.module, line 277 - Module file for Display Cache.
Code
function display_cache_entity_view_alter(&$build, $entity_type) {
// Disable display_cache by global setting.
if (variable_get('display_cache_disable', FALSE) === TRUE) {
return;
}
$view_mode = $build['#view_mode'];
$bundle = isset($build['#bundle']) ? $build['#bundle'] : NULL;
$settings = display_cache_get_settings($entity_type, $bundle, $view_mode);
$display_settings = $settings['default'];
// Cache if enabled.
if ($display_settings['use'] === DISPLAY_CACHE_ENABLED) {
if (!empty($build['#' . $entity_type])) {
$entity_id = entity_id($entity_type, $build['#' . $entity_type]);
}
elseif (!empty($build['#entity'])) {
$entity_id = entity_id($entity_type, $build['#entity']);
}
elseif ($entity_type === 'taxonomy_term') {
$entity_id = entity_id($entity_type, $build['#term']);
}
elseif ($entity_type === 'user') {
$entity_id = entity_id($entity_type, $build['#account']);
}
else {
// Create watchdog entry for unsupported entities.
watchdog('display cache', 'The entity type %entity_type seems to be unsupported until now. Please report this to the issue cue of Display Cache so we can fix this.', array(
'%entity_type' => $entity_type,
), WATCHDOG_WARNING);
return;
}
$keys = display_cache_get_cache_keys($entity_type, $entity_id, $view_mode, 'entity');
$build['#cache'] = array(
'keys' => $keys,
'bin' => DISPLAY_CACHE_CACHE_BIN,
'granularity' => $display_settings['granularity'],
);
}
}