Code snippet for Drupal content-type form dropdown

Section of a Drupal 6 form (admin) to provide a dropdown of current content-types within the system :

// get available node types
  $node_types = node_get_types();
 
  // fapi friendly array
  $node_types_array = array();
 
  foreach ($node_types as $node_type_obj) {
    $node_types_array[$node_type_obj->type] = $node_type_obj->name;
  }
 
  $form['my_node_type'] = array(
    '#type' => 'select',
    '#title' => t('Select node type'),
    '#default_value' => $defaults->my_node_type,
    '#options' => $node_types_array,
  );

Drupal 7 Version

// get available node types
$node_types = node_type_get_types();




Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. The supported tag styles are: <foo>, [foo].

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.
Bg