function panelizer_panels_cache_get in Panelizer 7.3
Same name and namespace in other branches
- 6 panelizer.module \panelizer_panels_cache_get()
- 7 panelizer.module \panelizer_panels_cache_get()
- 7.2 panelizer.module \panelizer_panels_cache_get()
Implements hook_panels_cache_get().
Get display edit cache for a display being edited.
The key is the second half of the key in this form: panelizer:TYPE:KEY
File
- ./
panelizer.module, line 1276 - The Panelizer module attaches panels to entities, providing default panels and allowing each panel to be configured independently by privileged users.
Code
function panelizer_panels_cache_get($argument) {
ctools_include('object-cache');
list($entity_type, $key) = explode(':', $argument, 2);
$cache = ctools_object_cache_get('panelizer_display_cache', $entity_type . ':' . $key);
// Keep $type because $entity_type can be 'default' which is not actually an
// entity type in that case.
$type = $entity_type;
if ($entity_type == 'default') {
list($entity_type, $bundle, $name) = @explode(':', $key, 3);
$get_default = TRUE;
}
$handler = panelizer_entity_plugin_get_handler($entity_type);
if (!$handler) {
return;
}
$entity_info = entity_get_info($entity_type);
$revision_key = isset($entity_info['entity keys']['revision']) ? $entity_info['entity keys']['revision'] : 'vid';
// Extract the entity ID and view mode.
list($entity_id, $view_mode) = explode(':', $key, 2);
// If this entity supports revisions, and a custom revision is being
// displayed, it's possible for the key to also include the revision ID.
if ($handler->supports_revisions && strpos($view_mode, ':') !== FALSE) {
list($entity_id, $view_mode, $vid) = explode(':', $key);
}
// If it's already cached, we still need to restore our contexts.
if (!empty($cache)) {
$cache->cached = TRUE;
if (!empty($get_default)) {
$panelizer = $handler
->get_default_panelizer_object($bundle, $name);
$cache->display->context = $handler
->get_contexts($panelizer);
// Set the storage_type and storage_id if either is empty.
if (empty($cache->display->storage_type)) {
$cache->display->storage_type = 'panelizer_default';
}
if (empty($cache->display->storage_id)) {
$cache->display->storage_id = $panelizer->name;
}
}
else {
$conditions = isset($vid) ? array(
$revision_key => $vid,
) : array();
$entities = entity_load($entity_type, array(
$entity_id,
), $conditions);
if (!empty($entities[$entity_id]) && !empty($entities[$entity_id]->panelizer[$view_mode])) {
$panelizer = $entities[$entity_id]->panelizer[$view_mode];
$cache->display->context = $handler
->get_contexts($panelizer, $entities[$entity_id]);
}
}
return $cache;
}
$cache = new stdClass();
// If it wasn't cached, create a new cache.
if (!empty($get_default)) {
$panelizer = $handler
->get_default_panelizer_object($bundle, $name);
$cache->display = $panelizer->display;
$cache->display->context = $handler
->get_contexts($panelizer);
// Set the storage_type and storage_id if either is empty.
if (empty($cache->display->storage_type)) {
$cache->display->storage_type = 'panelizer_default';
}
if (empty($cache->display->storage_id)) {
$cache->display->storage_id = $panelizer->name;
}
}
else {
$conditions = isset($vid) ? array(
$revision_key => $vid,
) : array();
$entities = entity_load($entity_type, array(
$entity_id,
), $conditions);
if (empty($entities[$entity_id]) || empty($entities[$entity_id]->panelizer[$view_mode])) {
return $cache;
}
list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entities[$entity_id]);
$panelizer = $entities[$entity_id]->panelizer[$view_mode];
$cache->display = $panelizer->display;
$cache->display->context = $handler
->get_contexts($panelizer, $entities[$entity_id]);
}
ctools_include('common', 'panels');
ctools_include('plugins', 'panels');
$cache_keys = array(
'panelizer',
$type,
$key,
);
if (isset($vid) && is_numeric($vid) && substr($key, strlen($vid) * -1) != $vid) {
$cache_keys[] = $vid;
}
$cache->display->cache_key = implode(':', $cache_keys);
// Set the allowed content types.
if (variable_get('panelizer_' . $type . ':' . $bundle . '_allowed_types_default', FALSE)) {
$cache->content_types = panels_common_get_allowed_types('panels_page', $cache->display->context);
}
else {
$cache->content_types = panels_common_get_allowed_types('panelizer_' . $type . ':' . $bundle, $cache->display->context);
}
// Set the allowed layout options.
$cache->display->allowed_layouts = panels_common_get_allowed_layouts(panelizer_get_allowed_layouts_option($type, $bundle));
return $cache;
}