How to create a new Entity/Content Type Programmatically in Drupal 7
Hello folks
Today I will share how to create a new entity/content type from code in a custom module.
To start you need to create a new module, lets call this new module staff.
1. Implement module.install
We need to create a file inside our module folder staff called staff.install
/**
* Implements hook_install().
*/
function staff_install() {
// Ensure the staff node type is available.
node_types_rebuild();
$types = node_type_get_types();
node_add_body_field( $types[ 'staff' ] );
}
2. Inform to Drupal about our new Entity/Content Type
Using the hook_node_info we inform to Drupal about our new Entity/Content Type, that hook must be implemented in staff.module file.
/**
* Implements hook_node_info().
*/
function staff_node_info() {
return array(
'slot' => array(
'name' => t('Staff Team'),
'base' => 'slot',
'description' => t('An Staff is used for users who belongs to the website team.'),
'title_label' => t('Title'),
)
);
}
Now you can use your new Entity/Contenty as a regular Entity/Content Type.
Enjoy IT
enzo







