Create a bundle programmatically? I've been trying to figure out this problem of allowing the user to dynamically create project request forms (add his own fields including drop downs, multiselects, etc...). The user needs a way to create multiple project request types (bundles, perhaps?), for different business units. I figured the entity / bundle relationship would be perfect for this. So here is my idea:

Use the Schema API to define my base table "project". Use the Entity API hook_entity_info() to tell Drupal about my new entity, pointing it to the "project" table. Now in this hook I can define bundles - which is great. But I need for the user to be able to create a bundle. Where is the entity_create_bundle($entity_type, $bundle) call?

Example:

Entity TYPE: Project (with common fields defined in DB, and it is fieldable)

Bundle: IT Project, HR Project - which share the common fields from Project

A project_type table will store additional grouping I need (project requests for business units). 

Now I've been reading Drupal 7 Module Development which has been great, and in chapter 6 they define an entity "artwork" that has a couple of bundles, "sculpture" and "painting". The way they describe the steps, is as if they are building an admin interface to create additional artwork types, but this is not true (from what I can tell). After finishing the chapter, I can only create entities of type "painting" or "sculpture".

How can I allow users to create bundles of the "project" entity type? 

Am I missing something or is the functionality not there [yet]?
Examining the default Node bundles

The Node module does not create the "Article" and "Basic page" Bundles itself.  After some digging I found the definitions for these bundles in the standard install profile's install file.

/profiles/standard/standard.install

  // Insert default pre-defined node types into the database. For a complete
  // list of available node type attributes, refer to the node type API
  // documentation at: http://api.drupal.org/api/HEAD/function/hook_node_info.
  $types = array(
    array(
      'type' =&gt; 'page',
      'name' =&gt; st('Basic page'),
      'base' =&gt; 'node_content',
      'description' =&gt; st("Use &lt;em&gt;basic pages&lt;/em&gt; for your static content, such as an 'About us' page."),
      'custom' =&gt; 1,
      'modified' =&gt; 1,
      'locked' =&gt; 0,
    ),
    array(
      'type' =&gt; 'article',
      'name' =&gt; st('Article'),
      'base' =&gt; 'node_content',
      'description' =&gt; st('Use &lt;em&gt;articles&lt;/em&gt; for time-sensitive content like news, press releases or blog posts.'),
      'custom' =&gt; 1,
      'modified' =&gt; 1,
      'locked' =&gt; 0,
    ),
  );

  foreach ($types as $type) {
    $type = node_type_set_defaults($type);
    node_type_save($type);
    node_add_body_field($type);
  }

  // clear the site cache


A few notes about this code


It doesn't use Entity API
st() function should only be used during a Drupal installation process
Node contains a lot of non Field API fields that it handles in node_type_save
Node calls field_attach_create_bundle to tell Field modules about the new bundle




Creating a bundle with the Entity API

I'm not sure how you've defined your entities, but if you've used Entity API then your bundle-creation code might look something like this:

$bundle = new stdClass();
$bundle-&gt;type = 'project_hr';
$bundle-&gt;label = t('HR Project');
$bundle-&gt;is_new = true;
$bundle-&gt;description = t("A super cool project");

$controller = new ProjectTypeController('project_type'); //assuming you defined this extension of EntityAPIController
$controller-&gt;save($bundle);




A note about Entities


An entity type is an abstract base class
A bundle is an extended entity type class
A field is a class member, property, variable or field instance
An entity is an object or instance of a base or extended class


More about entities