I have been trying to created a content type programmatically in Drupal 7. I notice that I should use the hook_node_info to generate the content type with the title and to add the body I should use the node_add_body_field
. I have been follow the examples modules 
So this is what I got as my code ...
non_recruiter.module
<?php
/**
* Implements hook_node_info().
*/
function non_recruiter_node_info() {
// We define the node type as an associative array.
return array(
'job_template_2' => array(
'name' => t('Job Template 2'),
'base' => 'job_template_2',
'description' => t('A content type for posting your jobs.'),
'title_label' => t('Job Template 2'),
'locked' => TRUE,
),
);
}
/**
* Implements hook_node_type_insert().
*/
function non_recruiter_node_type_insert($content_type) {
if ($content_type->type == 'job_template_2') {
$body_instance = node_add_body_field($content_type, t('Job Description'));
$body_instance['display']['non_recruiter_list'] = array(
'label' => 'hidden',
'type' => 'text_summary_or_trimmed',
);
// Save our changes to the body field instance.
field_update_instance($body_instance);
// Create all the fields we are adding to our content type.
foreach (_non_recruiter_installed_fields() as $field) {
field_create_field($field);
}
// Create all the instances for our fields.
foreach (_non_recruiter_installed_instances() as $instance) {
$instance['entity_type'] = 'node';
$instance['bundle'] = 'non_recruiter';
field_create_instance($instance);
}
}
}
/**
* Implements hook_form().
*/
function non_recruiter_form($node, $form_state) {
return node_content_form($node, $form_state);
}
function _non_recruiter_installed_fields() {
return array(
'non_recruiter_quantity' => array(
'field_name' => 'node_example_quantity',
'cardinality' => 1,
'type' => 'text',
),
);
}
function _non_recruiter_installed_instances() {
return array(
'non_recruiter_quantity' => array(
'field_name' => 'non_recruiter_quantity',
'label' => t('Quantity required'),
'type' => 'text',
'widget' => array(
'type' => 'text_textfield',
),
'display' => array(
'non_recruiter_list' => array(
'label' => 'hidden',
'type' => 'hidden',
),
),
),
);
}
So I took what they did and modify the code base on what I want.
My Goal is to have a content type that have the following fields...
- Job Title (title)
- Job Description (body)
- Quantity (text)
But I'm doing something wrong because the fields are empty. If I try to add new content using this content type this is what I got ...
An empty content type, without any fields.
Here is some extra information of how my Manage Fields & Display looks like..
Manage Fields
Manage Display
So, can anyone tell me why my fields are not showing up in my content type ?
hook_node_type_insert()
afterwards? If so it won't be run. Might be worth uninstalling and re-installing the module to checkhook_install()
rather than the insert hook - you could try using the same method as api.drupal.org/api/drupal/modules%21blog%21blog.install/…. It may be a case of addingnode_types_rebuild();
to the top of the insert hook instead. Though that doesn't seem right thinking about it