O.K., so I'm creating a module that creates a new node type. I followed the node_example in the Drupal API tutorials and everything is well and good: I can create a node with various text fields and checkboxes, no problem. The problem? Now I want to add an image field to my node. Still no big problem, except that when I call content_field_instance() on my image field, suddenly all my other fields (the text fields and checkboxes I had defined before) appear twice (including the title)!
Any idea what's going on?
Just to give you more info, here's how my node's hook_form() is structured:
function mycustomnode_form(&$node)
{
/*
* Set up the title and body
*/
$type = node_get_types('type', $node);
$title = array(
'#type' => 'textfield',
'#title' => check_plain($type->title_label),
'#required' => TRUE,
'#default_value' => $node->title,
'#weight' => -20,
);
$body = node_body_field($node, $type->body_label, $type->min_word_count);
$body['#weight'] = -15;
/**
* Include fields for this form
*/
/*
* The Picture/Image field.
*/
/* First, get the image field settings:*/
module_load_include('inc', 'mycustomnode', 'mycustomimage');
$picturefield = mycustomimagefield();
/* Now let CCK build/instantiate the image field on its own*/
module_load_include('inc', 'content', 'includes/content.crud');
content_field_instance_create($picturefield);
/*
* The Button Field
*/
module_load_include('inc', 'mycustomnode', 'mybuttons');
$buttonfield = mybuttonfield();
/**
* Terms and Conditions
*/
module_load_include('inc', 'mycustomnode', 'conditions');
$conditions = conditionsfield();
/**
* Now build the form
*/
$form = array($title, $body, $buttonfield, $conditions);
return $form;
}
where of course the files conditionsfield(), mybuttonfield(), and mycustomimagefield() are .inc files that simply define a field in the following style:
$buttonfield['buttonsfs'] = array(
'#type' => 'fieldset',
'#collapsible' => TRUE,
'#title' => t('My Buttons'),
'#description' => 'This field is just a bunch of checkboxes',
);
/*The enable checkboxes*/
$buttonfield['buttonsfs']['coolbutton']['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Cool Button'),
);
$buttonfield['buttonsfs']['neatbutton']['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Neat Button'),
);
$buttonfield['buttonsfs']['awesomebutton']['enable'] = array(
'#type' => 'checkbox',
'#title' => t('Awesome Button'),
);
So basically the node form all looks great if I disable the image field (i.e. if I comment out the line that calls content_field_instance), but if I call content_field_instance to insert the image field, all my other fields get displayed twice??
Any ideas? Thanks!
Comments
Personally I recommend the
Personally I recommend the Content Construct Kit (CCK) for creating custom content types (no coding required).
Ummm....
Umm...that is indeed what I am doing. And I need to create it programmatically. I am adding a cck image field to my custom node, PROGRAMMATICALLY. Did you read the original post?