If you've got a panelized node and you're using node_clone it'd be really nice if panelizer cloned the panels display and other panelizer settings, instead of just giving you the default display for that node type.

It might be possible to do all this just inside panelizer_nodeapi() with enough smarts about if we're trying to insert a $node with a real display ID but no nid, we can assume that's a cloned node and we should clone the display. Otherwise, node_clone() provides some hooks for us to alter $node during cloning so we can explicitly flag what's happening in $node so that panelizer_nodeapi() doesn't have to guess.

I need this ASAP for something I'm working on, so I'm assigning to myself and going to give it a go...

CommentFileSizeAuthor
#2 1205304-2.panelizer-node-clone.D6.patch2.59 KBdww

Comments

dww’s picture

First hurdle is a bug in node_clone itself: #654508-9: Add a way to determinee that a node was a clone. Ugh. For now, I'll at least see if I can get this working for the save-edit node_clone method. Stay tuned...

dww’s picture

Status: Active » Needs review
StatusFileSize
new2.59 KB

Notwithstanding the bug I mentioned in #1 where this doesn't work with node_clone's prepopulate method, the attached patch for D6 appears to be working great in my testing.

merlinofchaos’s picture

Status: Needs review » Reviewed & tested by the community

Since dww's testing shows it works, my eyeball review of the code thinks this is okay.

dww’s picture

Status: Reviewed & tested by the community » Fixed

Heh, except we don't want to try to clone the panelizer data on nodes that aren't panelized. ;) Fixed that, and pushed to D6:

http://drupal.org/commitlog/commit/18014/00a01e3638f82fe794470fd0da4d539...

Ported to D7, tested, and got that working, too. Oddly, I needed to reset the node_load() cache inside panelizer_node_insert() for this to work -- not sure why. Also, drupal_clone() is gone in favor of PHP 5's native clone method. And of course, there's no hook_nodeapi(), just hook_node_insert(). Anyway, since I got it working, I went ahead and committed and pushed:

http://drupal.org/commitlog/commit/18014/5e9891f51bad817528a22d413f6b9fd...

Note that node_clone itself is still pretty busted on D7 -- I had to use the patch from #986242: Drupal 7 fixes. to test this at all.

Status: Fixed » Closed (fixed)

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

projectalpha’s picture

Thanks. Reply #4 helped me a lot.

a.milkovsky’s picture

Issue summary: View changes

The issue is still relevant. Looks like this feature has gone in D7.
The issue is present is the 'Customize display' widget is on the page.

Panelizer is not cloned with node because the 'Customize display' widget, which has the name 'panelizer'. This spoils the saving logic because of the variables conflict.

The conflict happens here in entity_form_submit_build_entity():

  $values_excluding_fields = $info['fieldable'] ? array_diff_key($form_state['values'], field_info_instances($entity_type, $bundle)) : $form_state['values'];

My fix:

/**
 * Implements hook_clone_node_alter().
 */
function MODULE_clone_node_alter(&$node, $context) {
  $node->is_cloned = TRUE;
}

/**
 * Implements hook_form_BASE_FORM_ID_alter().
 */
function MODULE_form_node_form_alter(&$form, &$form_state, $form_id) {
  if (!empty($form_state['node']->is_cloned)) {
    unset($form['panelizer']);
  }
}

Created new issue #2811229: Panelizer is not cloned when 'Customize display' widget is present