Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically, I want a Drupal 7 content type with no "body" field

In Drupal 7, I have programmatically created a new content type with 2 new fields. Going to fill in the new content type, it displays a "Body" field that I do not want filled. Is there a way to programmatically install the new content type to hide the body field. I know I can use CSS to hide the body field, but, I think that is probably a kludge. I would like to use the correct programmatic method to hide the Body field.

like image 906
user1760422 Avatar asked Oct 21 '12 02:10

user1760422


2 Answers

You can do that using field_delete_instance()

Let us know if you need further assistance.

like image 71
Muhammad Reda Avatar answered Sep 25 '22 03:09

Muhammad Reda


Content types do not have the body field by default - it is usually added when creating the content type:

// add content types
$ctypes = _my_module_get_content_types();          // get content types
foreach($ctypes as $ctype => $data){
  if (!in_array($ctype, node_type_get_names())) {  // check for collisions
    $data = node_type_set_defaults($data);         // default *does not* add body field
    node_type_save($data);
    node_add_body_field($data);                    // add body here (typical usage)
  }
}

look around for the node_add_body_field() fn and remove it if present.

like image 22
doub1ejack Avatar answered Sep 23 '22 03:09

doub1ejack