diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index d053fd3..5a36b66 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -985,9 +985,20 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { // NOTE: This means that when exporting or deploying, we need to be sure // to set the display_is_modified flag to ensure this gets written. if (!empty($panelizer->display_is_modified)) { - // If this is a new entry or the entry is using a display from a default, - // clone the display. - if (!$update || empty($panelizer->did)) { + // Check if this display is shared and avoid changing other revisions + // displays. + $has_shared_display_args = array( + ':entity_type' => $this->entity_type, + ':entity_id' => $entity_id, + ':revision_id' => $revision_id, + ':did' => $panelizer->did, + ); + $has_shared_display = db_query('SELECT COUNT(did) FROM {panelizer_entity} WHERE entity_type = :entity_type AND entity_id = :entity_id AND revision_id <> :revision_id AND did = :did', $has_shared_display_args)->fetchField(); + + // If this is a new entry or the entry is using a display from a + // default, or revision is enabled and this is a shared display, clone + // the display. + if (!$update || empty($panelizer->did) || !empty($has_shared_display)) { $entity->panelizer[$view_mode] = $panelizer = $this->clone_panelizer($panelizer, $entity); // Update the cache key since we are adding a new display @@ -1023,6 +1034,13 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { $panelizer->view_mode = $view_mode; } + // Make sure we keep the same did as the original if the layout wasn't + // changed. + if (empty($panelizer->did) && !empty($entity->original->panelizer[$view_mode]->did)) { + $panelizer->did = $entity->original->panelizer[$view_mode]->did; + $update = array('entity_type', 'revision_id', 'view_mode'); + } + // Update the existing record. drupal_write_record('panelizer_entity', $panelizer, $update); }