I'm attempting to do a deep clone of a panelized node with a few Fieldable panels panes on it.
Once I worked out how to clone a panels page, I found that the text pane I had inserted on the first page, was only referenced on the clone, instead of properly cloned as I had hoped.

Where do I begin if I want this function?

I'm using Drupal 7.14, Node Clone 7.x-1.0-rc1, Panelizer 7.x-3.0-rc1, Fieldable Panels Panes
7.x-1.2 (and panopoly 7.x-1.0-beta6).

Comments

klim_’s picture

Have you resolved this issue?

lelizondo’s picture

Issue summary:View changes
Status:Active» Fixed

This is whay I did.

First, the problem was that FPP were not being cloned so the same FPP was referenced by the original node and the cloned node. So the solution was actually simple, loop through all the FPP in the original node, then load the FPP entity, create a new one with the same content and assign the new entity to the cloned node.

This is my code:

<?php
function mymodule_clone_node_alter(&$node, $context) {
   
$original = $context["original_node"];

    if(

$original->type == "my_content_type")    {
        if(isset(
$node->panelizer["page_manager"]->display)) {
                       
// The cloned node had the same UUID as the original, so I had to regenerate it
           
$node->panelizer["page_manager"]->display->uuid = uuid_generate();

            foreach(

$node->panelizer["page_manager"]->display->content as $entity) {
                              
// The cloned node had the same UUID as the original, so I had to regenerate it
               
$entity->uuid = uuid_generate();

                if(

$entity->type == "fieldable_panels_pane") {
                   
// clone each fpp and then assign the new fpid in the form of fpid
                   
list($subtype, $fpid) = explode(":", $entity->subtype);

                    if(

$subtype == "fpid") {
                       
// Load the entity
                       
$fpp = fieldable_panels_panes_load($fpid);

                       

// Create a new entity based on the same entity
                       
$fpp->fpid = null;
                       
$fpp->created = null;
                       
$fpp->timestamp = null;

                       

$newEntity = fieldable_panels_panes_save($fpp);

                       

// Assign the new id to the $entity->subtype
                       
$entity->subtype = "fpid:" . $newEntity->fpid;
                    }
                }
            }
        }
    }
}
?>

Status:Fixed» Closed (fixed)

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