Skip to content

Instantly share code, notes, and snippets.

@rintoug
Created March 25, 2017 10:09
Show Gist options
  • Save rintoug/4d12a967e27c23837d0f4f8ecd6e4364 to your computer and use it in GitHub Desktop.
Save rintoug/4d12a967e27c23837d0f4f8ecd6e4364 to your computer and use it in GitHub Desktop.
Create custom content type from module – Drupal 7
<?php
/**
* hook_install()
* This will automatically called when a module is installed
*/
function newslettereasy_install() {
_install_node_type();
}
function _install_node_type() {
$type = node_type_get_type('easynewsletter');
if (!$type) {
$type = node_type_set_defaults(array(
'type' => 'easynewsletter',
'name' => t('Easy newsletter'),
'base' => 'node_content',
'description' => t('A newsletter issue to be sent to subscribed email addresses.'),
'locked' => 0,
'custom' => 1,
'modified' => 1,
));
node_type_save($type);
node_add_body_field($type);
}
variable_set('easynewsletter_content_type_' . $type->type, TRUE);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment