I'm creating a module which provides a new node content type. I can extend the default node creation fields with my owns, but I would like to add some CCK fields too (like CCK ImageField) by default, NOT manually after enabling my module through the usual admin interface of Drupal's content type editor.

So for example here is my own form in my module that provides a new content type; this is what I would like to extend with a CCK ImageField (and later maybe add other CCK fields too):

 * Implementation of hook_form()
 * @see my_test_module_for_content_types_node_info()
function my_test_module_for_content_types_form($node){
    // Get metadata for this node type
    // (we use it for labeling title and body fields).
    // We defined this in seat_reservation_node_info()
    $type = node_get_types('type', $node);

    $form['title'] = array(
      '#type' => 'textfield',
      '#title' => check_plain($type->title_label),
      '#required' => TRUE,
      '#default_value' => $node->title,
      '#weight' => -5,
      '#maxlength' => 255,

    $form['body_filter']['body'] = array(
      '#type' => 'textarea',
      '#title' => check_plain($type->body_label),
      '#required' => TRUE,
      '#default_value' => $node->body,
      '#weight' => 7,

    $form['body_filter']['filter'] = filter_form($node->format);

    $form['test_blabla'] = array(
      '#type' => 'textfield',
      '#title' => t('This is my test field!!'),
      '#required' => TRUE,
      '#default_value' => isset($node->test_field) ? $node->test_field : '',
      '#weight' => 5,
      '#maxlength' => 255,

    return $form;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.