You are here

function panelizer_panels_cache_get in Panelizer 7.2

Same name and namespace in other branches
  1. 6 panelizer.module \panelizer_panels_cache_get()
  2. 7.3 panelizer.module \panelizer_panels_cache_get()
  3. 7 panelizer.module \panelizer_panels_cache_get()

Get display edit cache for a panel being edited.

The key is the second half of the key in this form: panelizer:TYPE:KEY;

File

./panelizer.module, line 840
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;
  }

  // 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);
    }
    else {
      $entities = entity_load($entity_type, array(
        $key,
      ));
      if ($entities[$key] && $entities[$key]->panelizer) {
        $panelizer = $entities[$key]->panelizer;
        $cache->display->context = $handler
          ->get_contexts($panelizer, $entities[$key]);
      }
    }
    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);
  }
  else {
    $entities = entity_load($entity_type, array(
      $key,
    ));
    if (empty($entities[$key]) || empty($entities[$key]->panelizer)) {
      return $cache;
    }
    list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entities[$key]);
    $panelizer = $entities[$key]->panelizer;
    $cache->display = $panelizer->display;
    $cache->display->context = $handler
      ->get_contexts($panelizer, $entities[$key]);
  }
  ctools_include('common', 'panels');
  $cache->display->cache_key = "panelizer:{$type}:{$key}";
  $cache->content_types = panels_common_get_allowed_types('panelizer_' . $type . ':' . $bundle, $cache->display->context);
  return $cache;
}