Last active
January 25, 2016 08:17
-
-
Save andeersg/cb73b543863cea2f6800 to your computer and use it in GitHub Desktop.
Simple script for copying fields from one bundle to another.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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