Assign Fields programatically to custom node defined by custom module Trying to convert a module from Drupal 6 to Drupal 7 which defines its own node type in hook_node_info.

Even though hook_node_info defines has_title and has_body to TRUE, how I can get these fields to appear on the node form? Previously, I used hook_form():

function mymodule_form(&amp;$node, $form_state) { 
  $type = node_get_types('type', $node);

  if ($type-&gt;has_title) {
    $form['title'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; check_plain($type-&gt;title_label),
        '#required' =&gt; TRUE,
        '#default_value' =&gt; $node-&gt;title,
        '#weight' =&gt; -25,
    );
  }

  if ($type-&gt;has_body) {
    $form['body_field'] = node_body_field($node, $type-&gt;body_label, $type-&gt;min_word_count);
    $form['body_field']['body']['#rows'] = 5;
    $form['body_field']['body']['#description'] = 'Enter a short message to present to the user.';
  }

  return $form;
}


In D6, this worked fine for me. In Drupal 7, hook_form has changed, and I am not quite following the documentation of it.

How can I utilize the Body and Title Field in core and assign them to this node type when the module is activated?

Furthermore, how can I define a new Field type to mimic Body (Long text with summary) to something of my choosing?
To add the body field to a content type, you use node_add_body_field(). To add a field that is not the body field, you use field_create_field(), if the field doesn't exist, and field_create_instance() to assign an instance of the field to an entity (e.g. a node or a user object).

As example of how to use those functions, you can look at standard_install(), which is the installation hook of the standard profile, that contains the following code:

  $field = array(
    'field_name' =&gt; 'field_' . $vocabulary-&gt;machine_name, 
    'type' =&gt; 'taxonomy_term_reference',
    'cardinality' =&gt; FIELD_CARDINALITY_UNLIMITED, 
    'settings' =&gt; array(
      'allowed_values' =&gt; array(
        array(
          'vocabulary' =&gt; $vocabulary-&gt;machine_name, 
          'parent' =&gt; 0,
        ),
      ),
    ),
  );
  field_create_field($field);

  $instance = array(
    'field_name' =&gt; 'field_' . $vocabulary-&gt;machine_name, 
    'entity_type' =&gt; 'node', 
    'label' =&gt; 'Tags', 
    'bundle' =&gt; 'article', 
    'description' =&gt; $vocabulary-&gt;help, 
    'widget' =&gt; array(
      'type' =&gt; 'taxonomy_autocomplete', 
      'weight' =&gt; -4,
    ), 
    'display' =&gt; array(
      'default' =&gt; array(
        'type' =&gt; 'taxonomy_term_reference_link', 
        'weight' =&gt; 10,
      ), 
      'teaser' =&gt; array(
        'type' =&gt; 'taxonomy_term_reference_link', 
        'weight' =&gt; 10,
      ),
    ),
  );
  field_create_instance($instance);


The code is adding a taxonomy term field to the content type "Article."