2

I'm trying to create a simple node_type in drupal 7 based on the core blog module.

This is my hook_install:

function node_link_install() {
  node_types_rebuild();
  $types = node_type_get_types();
  node_add_body_field($types['node_link']);
}

and this is then the hook_info in my node_link.module file:

function node_link_node_info() {
  return array(
    'node_link' => array(
      'name' => t('Node Link'),
      'base' => 'node_link',
      'description' => t('Just playing around'),
    )
  );
}

and here is my hook_uninstall:

function node_link_uninstall() {
  $result = db_query("SELECT n.nid FROM {node} n WHERE n.type = :type", array(':type' => 'node_link'));

  $nids = array();

  foreach ($result as $item) {
    array_push($nids, $item->nid);
  }

  if (count($nids)) {
    node_delete_multiple($nids);
  }

  drupal_uninstall_schema('node_link');
}

when I try to install the above module I get:

Notice: Undefined index: node_link in node_link_install() (line 10 of

drupal/sites/all/modules/custom/node_link/node_link.install). Notice: Trying to get property of non-object in node_add_body_field() (line 555 of drupal/modules/node/node.module). Notice: Trying to get property of non-object in node_add_body_field() (line 568 of drupal/modules/node/node.module). FieldException: Attempt to create an instance of field body without a bundle. in field_create_instance() (line 460 of drupal/modules/field/field.crud.inc).

Several things are puzzling me here:

1) why does this work for the blog module but not my module?

2) when I uninstall this module, the entry in the system table is not deleted

what am I missing?

1

The error is complaining that it can't save the body field because you haven't specified the bundle of the object. But more importantly I think you want to look into the Entity API rather than creating a 'node_type'.

In drupal there are nodes and there are types of nodes called content types. To make it more abstract, nodes are entities of type 'node'. Each content type is a 'bundle' of that entity type. Many things in drupal are entities, from users to comments to taxonomies.

If all you want to do is create a content type programatically, I think examples might have one. Otherwise just create the content type through configuration.

| improve this answer | |
  • Looks like the entity api actually is what I was looking for – kristian nissen Oct 14 '11 at 9:29

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.