hook_node_info or node_type_save? I've created a custom module that creates 2 content types in it's .install file (with node_type_save). This works fine, but now i have trouble implanting the hook_xxxx system. As the content types are already defined there is little need hook_node_info to define them again in the .module file, and even if i wanted to this will not work.

Now i can get around this by using hook_node_xxxx but i wonder if this is the right approach. It seems a bit dodgy to use the general hooks in a module which just defined those hooks.

Here is the code:

&lt;?php

/**
 * Implements hook_install().
 */
function vakantie_install() {

    $t = get_t();
    $content_types = array(
        'name1' =&gt; 'vakantie_blok',
        'name2' =&gt; 'vakantie_pagina',
    );

    $types = array( 
        array( 
            'type' =&gt; $content_types['name1'], 
            'name' =&gt; $t('Vakantie Blok'), 
            'base' =&gt; 'node_content', 
            'description' =&gt; $t('Maak een &lt;em&gt;Vakantie Blok&lt;/em&gt; item.'), 
            'custom' =&gt; 0, 
            'modified' =&gt; 1, 
            'locked' =&gt; 0, 
        ),
        array( 
            'type' =&gt; $content_types['name2'], 
            'name' =&gt; $t('Vakantie Pagina'), 
            'base' =&gt; 'node_content', 
            'description' =&gt; $t('Maak een &lt;em&gt;Vakantie Pagina&lt;/em&gt; item.'), 
            'custom' =&gt; 0, 
            '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, $t('Inhoud'));
    } 

    foreach ($content_types as $type) { 
        // add persistent variables that control settings
        variable_set('additional_settings__active_tab_' . $type, 'edit-menu');
        // 0 = disabled, 1 = optional, 2 = required
        variable_set('node_preview_' . $type, 1);
        // array(0 =&gt; 'status', 1 =&gt; 'promote', 2 =&gt; 'sticky', 3 =&gt; 'revision') remove to uncheck
        variable_set('node_options_' . $type, array());
        // 1 = Display author and date information, 0 = none
        variable_set('node_submitted_' . $type, 0);
        variable_set('menu_options_' . $type, array());
        variable_set('menu_parent_' . $type, 'main-menu:0');
    } 
}

/**
 * Implements hook_uninstall().
 */
function vakantie_uninstall() {

    $content_types = array(
        'name1' =&gt; 'vakantie_blok',
        'name2' =&gt; 'vakantie_pagina',
    );

    // gather all job nodes created and delete them
    $sql = 'SELECT nid FROM {node} n WHERE n.type = :type1 OR n.type = :type2';
    $result = db_query($sql, array(':type1' =&gt; $content_types['name1'], ':type2' =&gt; $content_types['name2']));
    $nids = array();
    foreach ($result as $row) {
        $nids[] = $row-&gt;nid;
    }
    node_delete_multiple($nids);

    // remove persistant variables that control settings
    foreach ($content_types as $type) { 
        variable_del('additional_settings__active_tab_' . $type);
        variable_del('node_preview_' . $type);
        variable_del('node_options_' . $type);
        variable_del('node_submitted_' . $type);
        variable_del('menu_options_' . $type);
        variable_del('menu_parent_' . $type);
    } 

    // delete our content type
    node_type_delete($content_types['name1']);
    node_type_delete($content_types['name2']);
}


Here the .module:

&lt;?php

function vakantie_node_view($node, $view_mode, $langcode) {
    if($node-&gt;type == 'vakantie_blok') {

        $extra_field = 'test_extra';

        $node-&gt;content['test'] = array(
            '#markup' =&gt; $extra_field, 
            '#weight' =&gt; 1, 
        );

        $node-&gt;content['test2'] = array(
            '#markup' =&gt; $extra_field, 
            '#weight' =&gt; -1, 
        );
    }
}
I would suggest doing as a Drupal module does: the Blog module. That is the correct code to use for a module that defines its own content type.


In the installation file, the code the Blog module uses is the following.

function blog_install() {
  // Ensure the blog node type is available.
  node_types_rebuild();
  $types = node_type_get_types();
  node_add_body_field($types['blog']);
}

In the module file, it implements the content type hooks, which are:


hook_form()
hook_node_info()
hook_view()



Another Drupal core module that implements its own content type is the Forum module. Differently from the Blog module, the Forum module adds a field to the nodes of its content type. The code it uses to set its content type is similar, though. (See forum_enable().) 

  // Ensure the forum node type is available.
  node_types_rebuild();
  $types = node_type_get_types();
  node_add_body_field($types['forum']);


Notice that Drupal core modules don't remove the content type they define, when they are uninstalled; eventually, they remove any field they attached to their content type. (See forum_uninstall().)

As side note, the string passed to t() contains English words, not in other languages.