moondog
moondog

Reputation: 1577

Drupal 6 hook: "field in a node-type has been added, modified or deleted"?

I see that hook_node_type() allows me to intercept and modify newly-created or newly-modified node-types. But apparently, hook_node_type() is not triggered when the node's field-definitions are created or modified.

For example, when I create a node-type "my_bio", hook_node_type() gets triggered. But if I then add a field "my_photo" to the "my_bio" node-type, then hook_node_type() is not triggered.

In Drupal 6, is there a way to write a hook that effectively extends hook_node_type(), so that the hook gets called when fields in a node-type are added or changed?

Alternatively, is there a hook that gets called when any field-definition is added or changed?

More specifically, this is what I am trying to accomplish: I have two custom formatters which are "mates": formatter_1 and formatter_2. When some field in a nodetype is added or modified, I check whether the field's formatter is formatter_1. If so, I then check whether the nodetype contains a "mate" for this field, i.e. a second field whose formatter is formatter_2. If not, I add a field-mate to this nodetype.

Upvotes: 1

Views: 251

Answers (1)

Clive
Clive

Reputation: 36955

EDITED

To address the update to your question...

CCK has a hook that gets fired whenever an instance of a field is attached to a node type, or an instance that is already attached to a node type is updated. It's called hook_content_fieldapi(); documentation seems to be pretty sketchy but it's mentioned in the content.crud.inc file as having the following operations:

  1. create instance
  2. read instance
  3. update instance
  4. delete instance

The hook implementation would look something like:

function mymodule_content_fieldapi($op, $field) {
  if ($op == 'create instance') {
    if ($field->foo == 'bar') {
      // Do something
    }
  }
}

As 'instances' essentially define the relationship between a node type and a field, this should be a good place to start what you're trying to do. I'd recommend dumping out the values of $field in the hook to see what variables you've got to work with.

Upvotes: 1

Related Questions