diff --git a/panelizer.module b/panelizer.module index 8140871..5420471 100644 --- a/panelizer.module +++ b/panelizer.module @@ -586,13 +586,13 @@ function panelizer_get_plugins_with_hook($hook) { */ function panelizer_entity_plugin_switcher_page($entity_type, $op) { $args = func_get_args(); - $js = !empty($_REQUEST['js']); // Load the $plugin information if ($handler = panelizer_entity_plugin_get_handler($entity_type)) { // replace the first two arguments: - $args[0] = $js; + $args[0] = !empty($_REQUEST['js']); $args[1] = $_POST; + // $args[3] = 'page_manager'; $method = 'page_' . $op; if (method_exists($handler, $method)) { return call_user_func_array(array($handler, $method), $args); @@ -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,13 @@ function panelizer_panels_cache_get($argument) { return; } + if ($handler->supports_revisions) { + list($entity_id, $view_mode, $vid) = explode(':', $key); + } + else { + list($entity_id, $view_mode) = explode(':', $key); + } + // If it's already cached, we still need to restore our contexts. if (!empty($cache)) { $cache->cached = TRUE; @@ -1058,8 +1065,8 @@ function panelizer_panels_cache_get($argument) { $cache->display->context = $handler->get_contexts($panelizer); } 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]); @@ -1078,8 +1085,8 @@ function panelizer_panels_cache_get($argument) { $cache->display->context = $handler->get_contexts($panelizer); } 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 +1099,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 +1124,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 +1146,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 +1163,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; @@ -1418,3 +1427,17 @@ function panelizer_operations() { return $operations; } +/** + * Implements hook_workbench_moderation_node_history_view_alter(). + */ +function panelizer_workbench_moderation_node_history_view_alter(&$rows) { + foreach ($rows as $key => &$row) { + $published = FALSE; + if (in_array('published-revision', $row['class'])) { + $published = TRUE; + } + if (!$published) { + $row['data']['revision'] .= ' | ' . l('Panelizer', 'node/' . arg(1) . '/revisions/' . $row['data']['vid'] . '/panelizer'); + } + } +} diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index dcf0446..c3a6cc7 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -283,7 +283,7 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { 'page callback' => 'panelizer_entity_plugin_switcher_page', 'page arguments' => array($this->entity_type, 'overview', $position), 'type' => MENU_DEFAULT_LOCAL_TASK, - 'weight' => 11, + 'weight' => -100, ) + $base; // Put in all of our view mode based paths. @@ -312,6 +312,37 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path]['file path'] = $operation['file path']; } } + + if ($this->supports_revisions) { + $rev_base = $base; + $rev_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, + ) + $rev_base; + $items[$this->plugin['entity path'] . '/revisions/%/panelizer']['type'] = MENU_CALLBACK; + + foreach (panelizer_operations() as $path => $operation) { + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/' . $path] = array( + 'title' => $operation['menu title'], + 'page callback' => 'panelizer_entity_plugin_switcher_page', + 'page arguments' => array($this->entity_type, $path, $position), + 'access arguments' => array($this->entity_type, 'access', 'admin', $position, $path), + 'weight' => $weight++, + ) + $rev_base; + if (isset($operation['file'])) { + $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path]['file'] = $operation['file']; + } + if (isset($operation['file path'])) { + $items[$this->plugin['entity path'] . '/panelizer/' . $view_mode . '/' . $path]['file path'] = $operation['file path']; + } + } + $items[$this->plugin['entity path'] . '/revisions/%/panelizer/content']['type'] = MENU_DEFAULT_LOCAL_TASK; + } } } @@ -1264,10 +1295,22 @@ 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_entities = entity_load($this->entity_type, array($entity_id)); + $current_entity = array_pop($current_entities); + 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 +1543,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, );