You are here

public function PanelizerEntityDefault::clone_panelizer in Panelizer 7.3

Same name and namespace in other branches
  1. 7.2 plugins/entity/PanelizerEntityDefault.class.php \PanelizerEntityDefault::clone_panelizer()

Create a new, scrubbed version of a panelizer object.

2 calls to PanelizerEntityDefault::clone_panelizer()
PanelizerEntityDefault::hook_entity_insert in plugins/entity/PanelizerEntityDefault.class.php
PanelizerEntityDefault::hook_entity_update in plugins/entity/PanelizerEntityDefault.class.php

File

plugins/entity/PanelizerEntityDefault.class.php, line 2050
Base class for the Panelizer Entity plugin.

Class

PanelizerEntityDefault
Base class for the Panelizer Entity plugin.

Code

public function clone_panelizer($panelizer, $entity) {

  // When services tries to send nodes via JSON, the $panelizer here gets
  // accidentally cast as an array. By casting it back as an object here we
  // can code defensively and pre-empt any fatal errors below when calling
  // clone.
  $panelizer = (object) $panelizer;
  $panelizer->display = (object) $panelizer->display;
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($this->entity_type, $entity);
  $panelizer_clone = clone $panelizer;

  // Clean out all of the UUIDs.
  $panelizer_clone->display->uuid = NULL;
  foreach ($panelizer_clone->display->content as &$pane) {
    $pane->uuid = NULL;
  }

  // In order to ensure we don't actually use and modify the default display,
  // we export and re-import it.
  $code = panels_export_display($panelizer->display);
  ob_start();
  eval($code);
  ob_end_clean();
  $panelizer_clone->display = $display;
  $panelizer_clone->did = NULL;
  $panelizer_clone->name = NULL;
  $panelizer_clone->entity_type = $this->entity_type;
  $panelizer_clone->entity_id = $entity_id;

  // The (int) ensures that entities that do not support revisions work
  // since the revision_id cannot be NULL.
  $panelizer_clone->revision_id = (int) $revision_id;

  // Trigger hook_panelizer_clone_panelizer().
  foreach (module_implements('panelizer_clone_panelizer') as $module) {
    $function = $module . '_panelizer_clone_panelizer';
    $function($panelizer_clone);
  }
  return $panelizer_clone;
}