function drush_field_clone

8.0.x field.drush.inc drush_field_clone($source_field_name, $target_field_name)
6.x field.drush.inc drush_field_clone($source_field_name, $target_field_name)
7.x field.drush.inc drush_field_clone($source_field_name, $target_field_name)
4.x field.drush.inc drush_field_clone($source_field_name, $target_field_name)
5.x field.drush.inc drush_field_clone($source_field_name, $target_field_name)

File

commands/core/field.drush.inc, line 266
Field API's drush integration

Code

function drush_field_clone($source_field_name, $target_field_name) {
  if (!$info = field_info_field($source_field_name)) {
    return drush_set_error(dt('!source not found in field list.', array('!source' => $source_field_name)));
  }

  unset($info['id']);
  $info['field_name'] = $target_field_name;
  $target = drush_op('field_create_field', $info);

  foreach ($info['bundles'] as $entity_type => $bundles) {
    foreach ($bundles as $bundle) {
      $instance = field_info_instance($entity_type, $source_field_name, $bundle);
      $instance['field_name'] = $target_field_name;
      unset($instance['id']);
      $instance['field_id'] = $target['id'];
      drush_op('field_create_instance', $instance);
      $urls[] = drush_url(drush_field_ui_bundle_admin_path($entity_type, $bundle) . '/fields/' . $target_field_name, array('absolute' => TRUE));
    }
  }

  drush_print(implode(' ', $urls));
}