I've been duplicating panelizer nodes in 7.x-2.x in a custom action, which seems to duplicate the panelizer content with no problems.

However I'm planning on updating to panelizer-7.x-3.x soon, and was hoping I could get suggestions on how best to duplicate a node that has user customized panelizer content. I looked through the panelizer module and didn't see anything promising that existed already.

The only approach I can currently see is to duplicate the node with a default panelizer['page_manager'] object (basically unset the old panelizer object), and then use the functions/API provided by panels to add the display to the new node (after entity_save). Is this a good route?

Thanks in advance for any help you guys can give...

Comments

kenianbei’s picture

This is what I've ended up with, which works, though I'm not sure how efficient it is:

    // Clone the node.
    $new_node = clone $node;
    
    // Prepare to save.
    $new_node->nid = NULL;
    $new_node->vid = NULL;
    $new_node->created = NULL;
    $new_node->path = NULL;
    $new_node->files = array();

    // Process the panelizer if there is one attached to this node.
    if ($new_node->panelizer) {
 
      // Set variables and remove current panelizer, which will give us a new panelizer object.
      $panelizer = $new_node->panelizer;
      $display = $panelizer['page_manager']->display;
      unset($new_node->panelizer);
      
      // Create a new display to add to the panelizer.
      $code = panels_export_display($display);
      eval($code);
      panels_save_display($display);

      // Save the new node in order to set a new panelizer object.
      entity_save('node', $new_node);
      
      // Load the new node to get the new panelizer information.
      $new_node = node_load($new_node->nid);

      // Set new values for the new panelizer node.
      $new_node->panelizer['page_manager']->display = $display;
      $new_node->panelizer['page_manager']->new = TRUE;
      $new_node->panelizer['page_manager']->did = $display->did;
      $new_node->panelizer['page_manager']->entity_id = $new_node->nid;
      $new_node->panelizer['page_manager']->entity_type = 'node';
      $new_node->panelizer['page_manager']->link_to_entity = $new_node->nid;
    }
    
    // Save the new node.
    entity_save('node', $new_node);

Lowkey’s picture

I have had the same problem and spent some time looking through the code.
I'm using Drupal 7.14, Node Clone 7.x-1.0-rc1, Panelizer 7.x-3.0-rc1 (and panopoly 7.x-1.0-beta6)

Here's my solution for the moment:
In the file /path/to/drupal/sites/all/modules/panelizer/plugins/entity/PanelizerEntityDefault.class.php find line 907 and change this:

        // And write the new record.
        drupal_write_record('panelizer_entity', $clone);

to this:

        // And write the new record.
        drupal_write_record('panelizer_entity', $panelizer);

That should fix the problem.

merlinofchaos’s picture

Category: support » bug
Status: Active » Fixed

Ooh. That is definitely a bug report. $clone should have been removed and is clearly a leftover. Excellent catch. Made the change in #2, and committed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

Removed code.