I'm developing a module that create a several new content types:
function create_new_content_type($type, $name){
$t = get_t();
$new_node = array(
'type' => $type,
'name' => $name,
'base' => 'node_content',
'custom' => TRUE,
//'description' => 'This is an example node type with a few fields.',
);
$content_type = node_type_set_defaults($new_node);
node_add_body_field($content_type);
// Check if we create content type or update.
$status = node_type_save($content_type);
// Replacement rule for the messages.
$t_args = array('%name' => $content_type->name);
if ($status == SAVED_NEW) { // create case
watchdog('node', 'Added content type %name.', $t_args, WATCHDOG_NOTICE, l($t('view'), 'admin/structure/types'));
return true;
}
return false;
}
after that creates a new fields for that type (for example):
function createTextField($name, $label, $bundle, $required=FALSE){
// Create the field base.
$field = array(
'field_name' => $name,
'type' => 'text',
);
field_create_field($field);
// Create the field instance on the bundle.
$instance = array(
'field_name' => $name,
'entity_type' => 'node',
'label' => $label,
'bundle' => $bundle,
// If you don't set the "required" property then the field wont be required by default.
'required' => $required,
'widget' => array(
'type' => 'textfield',
),
);
field_create_instance($instance);
}
Lets assume I have already existed field with name field_my_custom
how can I attach it to my new created content type? (if I understand right in the method above I only create new fields).