Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By sharif.elshobkshy on
If you want to learn how to create a custom content type with custom fields.
$type = node_type_load('content_type_name');
if (!$type) {
$type = array(
'type' => 'content_type_name',
'name' => t('Content Type Human Name'),
'base' => 'node_content',
'description' => t(
"Description of <em>Content Type Human Name</em> goes here."),
'custom' => 1,
'modified' => 1,
'locked' => 0,
);
$type = node_type_set_defaults($type);
// Create a custom Text Field
$field = array(
'field_name' => 'my_text_field_name',
'type' => 'text',
'entity_types' => array('node'),
);
$field = field_create_field($field);
$instance = array(
'field_name' => 'my_text_field_name',
'entity_type' => 'node',
'bundle' => 'content_type_name',
'label' => t('Custom Field Human Name'),
'widget' => array('type' => 'text_textfield'),
);
$instance = field_create_instance($instance);
// Create URL Field
node_type_save($type);
node_add_body_field($type);
}
Comments
You are starting to look like
You are starting to look like a spammer with these posts, you should consider joining the document team as this has been cover elsewhere.
_
Yes, please consider adding your documentation to the documentation pages rather than random forum posts.
Custom content type
Refer this tutorial https://www.betamark.com/creating-custom-content-type-programmatically-d...