diff --git a/panelizer.module b/panelizer.module index 8140871..43fa1b6 100644 --- a/panelizer.module +++ b/panelizer.module @@ -1035,7 +1035,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. @@ -1050,6 +1050,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; @@ -1059,7 +1063,8 @@ function panelizer_panels_cache_get($argument) { } else { list($entity_id, $view_mode) = explode(':', $key); - $entities = entity_load($entity_type, array($entity_id)); + $conditions = (isset($vid) ? array('vid' => $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]); @@ -1079,7 +1084,8 @@ function panelizer_panels_cache_get($argument) { } else { list($entity_id, $view_mode) = explode(':', $key); - $entities = entity_load($entity_type, array($entity_id)); + $conditions = (isset($vid) ? array('vid' => $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; } @@ -1092,7 +1098,7 @@ function panelizer_panels_cache_get($argument) { ctools_include('common', 'panels'); ctools_include('plugins', 'panels'); - $cache->display->cache_key = "panelizer:$type:$key"; + $cache->display->cache_key = "panelizer:$type:$key" . (!empty($vid) ? ":$vid" : ''); // Set the allowed content types if (variable_get('panelizer_' . $type . ':' . $bundle . '_allowed_types_default', FALSE)) { @@ -1117,18 +1123,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); } /** @@ -1141,12 +1145,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; @@ -1155,7 +1162,8 @@ function panelizer_panels_cache_save($argument, $cache) { } else { list($entity_id, $view_mode) = explode(':', $key); - $entities = entity_load($entity_type, array($entity_id)); + $conditions = (isset($vid) ? array('vid' => $vid) : array()); + $entities = entity_load($entity_type, array($entity_id), $conditions); if ($entities[$entity_id] && $entities[$entity_id]->panelizer[$view_mode]) { $entities[$entity_id]->panelizer[$view_mode]->display = $cache->display; $entities[$entity_id]->panelizer[$view_mode]->display_is_modified = TRUE; diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index dcf0446..76dcfeb 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -297,6 +297,51 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { 'weight' => $weight++, ) + $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' => $weight++, + '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' => $weight++, + ) + $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' => $weight++, + ) + $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' => $weight++, + ) + $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' => $weight++, + ) + $base; + } + foreach (panelizer_operations() as $path => $operation) { $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path] = array( 'title' => $operation['menu title'], @@ -1264,10 +1309,21 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { function entity_base_url($entity, $view_mode = NULL) { list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity); - $bits = explode('/', $this->plugin['entity path']); + $path_elements[] = $entity_id; + + $path = $this->plugin['entity path']; + if ($this->supports_revisions) { + $current_entity = entity_load($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); } } @@ -1500,7 +1556,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, $view_mode))), + 'display cache' => panels_edit_cache_get(implode(':', array('panelizer', $this->entity_type, $entity_id, $view_mode, $revision_id))), 'no_redirect' => TRUE, );