hook_node_type

  1. drupal
    1. drupal6
    2. drupal7 node.api.php
Versionen
drupal6 – drupal7 hook_node_type($op, $info)

Act on node type changes.

This hook allows modules to take action when a node type is modified.

Übergabeparameter

$op What is being done to $info. Possible values:

  • "delete"
  • "insert"
  • "update"

Most modules will not need the update or insert operations, because form fields you add to the node type editing form will be automatically saved as variables. For instance, if you add a field called 'my_module_foo' to content type 'machine_name', its value will be saved as variable 'my_module_foo_machine_name' (and if the machine name is updated, the variables will be updated appropriately).

$info The node type object on which $op is being performed.

Verwandte Themen

Code

developer-docs/hooks/node.php, line 98

<?php
function hook_node_type($op, $info) {
  switch ($op) {
    case 'delete':
      // Example from comment.module.
      variable_del('comment_' . $info->type);
      break;
    case 'update':
      // Here is an example where you do need an update operation (from the
      // book module), because the simple default case doesn't cover what needs
      // to be done.
      if (!empty($type->old_type) && $type->old_type != $type->type) {
        // Update the list of node types that are allowed to be added to books.
        $allowed_types = variable_get('book_allowed_types', array('book'));
        $key = array_search($type->old_type, $allowed_types);
        if ($key !== FALSE) {
          $allowed_types[$type->type] = $allowed_types[$key] ? $type->type : 0;
          unset($allowed_types[$key]);
          variable_set('book_allowed_types', $allowed_types);
        }
        // Update the setting for the "Add child page" link.
        if (variable_get('book_child_type', 'book') == $type->old_type) {
          variable_set('book_child_type', $type->type);
        }
      }
      break;
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen