Hello,

I've been using node clone to copy content which is also using Field Collections. Within the collection are text, attachment and link fields. After cloning the node, changes that I make to pre-existing fields on the clone are also taking effect on the original. E.g. removing attachments, adding links using add another item, editing the text field etc. The changes are also made in the other direction - edits to the original affect clone.

Additionally, the Field Collection is set to unlimited, which allows me to add more items to the node. Items added after the clone do not appear to be affected as described above.

Thoughts?

Comments

lelizondo’s picture

I'm having the same problem using Panelizer and Page Manager

DamienMcKenna’s picture

I'm going to work on the Panelizer compatibility on Monday-ish, will report back in #2375563: Compatibility with Node Clone.

lelizondo’s picture

The problem is that the fieldable panels panes id is just copied as it. I had to loop through all of the FPP, clone them and then assign the new ids to the new node. If you need to see my implementation I'd be glad to share it but I'm afraid is not a general solution.

pwolanin’s picture

Category: Bug report » Feature request

I'm honestly not sure how field collections are implemented. This is not something I would really expect to work OOTB.

Please indicate if you are willing to provide a patch for Field Collections support, otherwise I'll just close this.

lelizondo’s picture

I don't think this will work out of the box ether, this is the code I'm using in case anyone needs it:

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

	if($original->type == "your_content_type")	{
		if(isset($node->panelizer["page_manager"]->display)) {
			$node->panelizer["page_manager"]->display->uuid = uuid_generate();

			foreach($node->panelizer["page_manager"]->display->content as $entity) {
				$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;
					}
				}
			}
		}
	}
}
?>
DamienMcKenna’s picture

Title: Changes to clone affecting original » Compatibility with Field Collections
Version: 7.x-1.0-rc2 » 7.x-1.x-dev

Lets simplify this request. The desire is for data stored in Field Collections to be exportable via Node Clone.

DamienMcKenna’s picture

FYI Field Collections are stored as an entity object. And I don't think this issue should be closed until it's made to work.

pwolanin’s picture

@DamienMcKenna - I really don't think this belongs in the base module. Field collections are neither simple to copy (I expect) nor part of core or very central contrib.

DamienMcKenna’s picture

So, do you think Field Collection should implement hook_clone_node_alter() to load the full objects prior to cloning?

pwolanin’s picture

Did you look at the add-on module referenced here: #2279659: Point users to the Field Collection Node Clone module

DamienMcKenna’s picture

Status: Active » Closed (duplicate)

.. oh. I wish they'd built it as a patch for either Node Clone or Field Collection, rather than needing a third module.