I'm writing a custom module, which I've done before, but this is the first time I've tried to create a content type with fields. I implemented hook_node_info and the Content Type is showing up in the list of Content types in the dropdown from admin_menu, however, when I browse to admin/structure/types
it is not listed.
I implemented hook_install and grabbed some code I found on another SO question. I have the code print out some debug info to my error log and it LOOKS like it all works, but when I browse to the Structure Content Type it doesn't show the field I added.
Here are hooks:
function mymod_node_info() {
return array(
'mymod_content' => array(
'name' => t('My Mod'),
'base' => 'mymod_content',
'description' => t('A Description'),
)
);
}
function mymod_install() {
error_log('mymod_install');
$types = node_type_get_types();
if ( ! field_info_field('field_mymod_myfile') ) {
$field = array(
'field_name' => 'field_mymod_myfile',
'type' => 'file',
);
$created_field = field_create_field($field);
error_log('---- field_create_field -----');
error_log(var_export($created_field, true));
}
$instance = array(
'field_name' => 'field_mymod_myfile',
'entity_type' => 'mymod_content',
'bundle' => 'mymod_content',
'required' => TRUE,
);
$created_instance = field_create_instance($instance);
error_log('---- field_create_instance -----');
error_log(var_export($created_instance, true));
}
I can see a table called field_data_field_mymod_myfile
in the database, so I know the first part worked. However, the table is empty.
The error log shows the field_create_instance()
method returned this:
array (
'field_name' => 'field_mymod_myfile',
'entity_type' => 'mymod_content',
'bundle' => 'mymod_content',
'required' => true,
'field_id' => '5',
)
Why doesn't my field show up on this content type?