I would like a GUI that will allow me to reset fields for content types that are clonable.
At the minimum a PHP textbox that will accept code to initialize or reset fields to defaults AFTER cloning.

Comments

ibandyop’s picture

Component: Code » Documentation
Assigned: Unassigned » ibandyop
Status: Active » Needs review

For those seeking a D7 solution to reset field entities after cloning. The following code should be customized to match the fields in of your content type.

  • create a module called mymodule and add the function like the one described.
  • make sure you match fields to your content type mycontenttype
  • dsm() and dpm() are debugging functions and need the devel module. Should help you figure out your field setup

/**
 * Implements hook_clone_node_alter
 */

function mymodule_clone_node_alter(&$node, $context) {

//dsm($context['method']);

if ( ($context['method'] == 'prepopulate') and ($node->type == 'mycontenttype') ) {

  //dpm( $node);
  $node->title = $context['original_node']->title; // set original title remove 'Clone of' prefix

  $node->field_expect_topay['und']['0']['value'] = '$1000 - $2500'; 
  $node->field_quality_of_products['und']['0']['value'] = 'High Quality';

}


References:
http://drupal.org/node/386440
http://drupal.org/node/1256478
http://drupal.org/node/1167756

pwolanin’s picture

Status: Needs review » Fixed

Thanks for the docs

Status: Fixed » Closed (fixed)

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