diff --git a/plugins/entity/PanelizerEntityDefault.class.php b/plugins/entity/PanelizerEntityDefault.class.php index 20ff5e4..1eba29e 100644 --- a/plugins/entity/PanelizerEntityDefault.class.php +++ b/plugins/entity/PanelizerEntityDefault.class.php @@ -939,6 +939,11 @@ abstract class PanelizerEntityDefault implements PanelizerEntityInterface { $view_mode = 'page_manager'; } + // Do type checking to make sure this is an object and not an array. + if (is_array($panelizer)) { + $panelizer = (object) $panelizer; + } + if ($this->supports_revisions) { if (empty($panelizer->revision_id) || $panelizer->revision_id != $revision_id) { $panelizer->revision_id = $revision_id; @@ -962,9 +967,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 @@ -1000,6 +1016,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'); + } + drupal_write_record('panelizer_entity', $panelizer, $update); } }