diff --git a/panelizer.module b/panelizer.module index d8269ce..ea4339b 100644 --- a/panelizer.module +++ b/panelizer.module @@ -826,7 +826,7 @@ function panelizer_context_cache_clear($entity_type, $key) { 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); + $cache = ctools_object_cache_get('panelizer_display_cache', $argument); // Keep $type because $entity_type can be 'default' which is not actually an // entity type in that case. @@ -841,6 +841,10 @@ function panelizer_panels_cache_get($argument) { return; } + if ($handler->supports_revisions) { + list($key, $vid) = explode(':', $key, 2); + } + // If it's already cached, we still need to restore our contexts. if (!empty($cache)) { $cache->cached = TRUE; @@ -849,7 +853,8 @@ function panelizer_panels_cache_get($argument) { $cache->display->context = $handler->get_contexts($panelizer); } else { - $entities = entity_load($entity_type, array($key)); + $conditions = (isset($vid) ? array('vid' => $vid) : array()); + $entities = entity_load($entity_type, array($key), $conditions); if ($entities[$key] && $entities[$key]->panelizer) { $panelizer = $entities[$key]->panelizer; $cache->display->context = $handler->get_contexts($panelizer, $entities[$key]); @@ -868,7 +873,8 @@ function panelizer_panels_cache_get($argument) { $cache->display->context = $handler->get_contexts($panelizer); } else { - $entities = entity_load($entity_type, array($key)); + $conditions = (isset($vid) ? array('vid' => $vid) : array()); + $entities = entity_load($entity_type, array($key), $conditions); if (empty($entities[$key]) || empty($entities[$key]->panelizer)) { return $cache; } @@ -880,7 +886,7 @@ function panelizer_panels_cache_get($argument) { } ctools_include('common', 'panels'); - $cache->display->cache_key = "panelizer:$type:$key"; + $cache->display->cache_key = "panelizer:$type:$key" . (!empty($vid) ? ":$vid" : ''); $cache->content_types = panels_common_get_allowed_types('panelizer_' . $type . ':' . $bundle, $cache->display->context); return $cache; @@ -890,18 +896,16 @@ function panelizer_panels_cache_get($argument) { * Store a display edit in progress in the page cache. */ function panelizer_panels_cache_set($argument, $cache) { - list($type, $key) = explode(':', $argument, 2); ctools_include('object-cache'); - ctools_object_cache_set('panelizer_display_cache', $type . ':' . $key, $cache); + ctools_object_cache_set('panelizer_display_cache', $argument, $cache); } /** * Save all changes made to a display using the Page Manager page cache. */ function panelizer_panels_cache_clear($argument, $cache) { - list($type, $key) = explode(':', $argument, 2); ctools_include('object-cache'); - ctools_object_cache_clear('panelizer_display_cache', $type . ':' . $key); + ctools_object_cache_clear('panelizer_display_cache', $argument); } /** @@ -914,12 +918,15 @@ function panelizer_panels_cache_save($argument, $cache) { list($entity_type, $bundle, $name) = @explode(':', $key, 3); $get_default = TRUE; } - $handler = panelizer_entity_plugin_get_handler($entity_type); if (!$handler) { return; } + if ($handler->supports_revisions) { + list($key, $vid) = explode(':', $key, 2); + } + if (!empty($get_default)) { $panelizer = $handler->get_default_panelizer_object($bundle, $name); $panelizer->display = $cache->display; @@ -927,7 +934,8 @@ function panelizer_panels_cache_save($argument, $cache) { ctools_export_crud_save('panelizer_defaults', $panelizer); } else { - $entities = entity_load($entity_type, array($key)); + $conditions = (isset($vid) ? array('vid' => $vid) : array()); + $entities = entity_load($entity_type, array($key), $conditions); if ($entities[$key] && $entities[$key]->panelizer) { $entities[$key]->panelizer->display = $cache->display; $entities[$key]->panelizer->display_is_modified = TRUE; diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index c9dc149..0d34df2 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -310,6 +310,51 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { 'access arguments' => array($this->entity_type, 'access', 'admin', $position, 'settings'), 'weight' => 14, ) + $base; + + if ($this->supports_revisions) { + $base['load arguments'] = array($position + 2); + $items[$this->plugin['entity path'] . '/revisions/%/panelizer'] = array( + 'title' => 'Panelizer', + // make sure this is accessible to panelize entities with no defaults. + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, 'content', $position), + 'weight' => 11, + 'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE, + ) + $base; + $items[$this->plugin['entity path'] . '/revisions/%/panelizer']['type'] = MENU_CALLBACK; + + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/content'] = array( + 'title' => 'Content', + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, 'content', $position), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => 11, + ) + $base; + + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/layout'] = array( + 'title' => 'Layout', + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, 'layout', $position), + 'access arguments' => array($this->entity_type, 'access', 'admin', $position, 'layout'), + 'weight' => 12, + ) + $base; + + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/context'] = array( + 'title' => 'Context', + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, 'context', $position), + 'access arguments' => array($this->entity_type, 'access', 'admin', $position, 'context'), + 'weight' => 13, + ) + $base; + + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/settings'] = array( + 'title' => 'Settings', + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, 'settings', $position), + 'access arguments' => array($this->entity_type, 'access', 'admin', $position, 'settings'), + 'weight' => 14, + ) + $base; + } } if (!empty($this->entity_admin_root)) { @@ -1132,10 +1177,21 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { $display = $panelizer->display; $display->context = $this->get_contexts($panelizer, $entity); - $bits = explode('/', $this->plugin['entity path']); + $path_elements[] = $entity_id; + + $path = $this->plugin['entity path']; + if ($this->supports_revisions) { + $current_entity = entity_load_single($this->entity_type, $entity_id); + if ($revision_id !== $current_entity->vid) { + $path_elements[] = $revision_id; + $path .= '/revisions/%'; + } + } + + $bits = explode('/', $path); foreach ($bits as $count => $bit) { if (strpos($bit, '%') === 0) { - $bits[$count] = $entity_id; + $bits[$count] = array_shift($path_elements); } } @@ -1177,7 +1233,7 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { $form_state = array( 'entity' => $entity, 'revision info' => $this->entity_allows_revisions($entity), - 'display cache' => panels_edit_cache_get(implode(':', array('panelizer', $this->entity_type, $entity_id))), + 'display cache' => panels_edit_cache_get(trim(implode(':', array('panelizer', $this->entity_type, $entity_id, $revision_id)),':')), 'no_redirect' => TRUE, );