Skip to content

Instantly share code, notes, and snippets.

@andeersg
Last active January 25, 2016 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andeersg/cb73b543863cea2f6800 to your computer and use it in GitHub Desktop.
Save andeersg/cb73b543863cea2f6800 to your computer and use it in GitHub Desktop.
Simple script for copying fields from one bundle to another.
<?php
$entity_type = '';
$old_bundle = '';
$new_bundle = '';
$fields = array(
'field_name',
);
foreach ($fields as $field) {
$info = field_info_instance($entity_type, $field, $old_bundle);
$info_new = field_info_instance($entity_type, $field, $new_bundle);
if ($info && !$info_new) {
$info['bundle'] = $new_bundle;
unset($info['id']);
unset($info['field_id']);
field_create_instance($info);
drupal_set_message(t('Created instance of !field for !bundle', array('!field' => $field, '!bundle' => $new_bundle)));
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment