Search code examples
drupaldrupal-7

Drupal domain access auto create content


I am using Drupal's domain access module to create micro sites in a white label system. Is there a way of automatically creating nodes with default content for each site?


Solution

  • Use hook_domain_insert() this will give you the id of the domain that has just been created in the $domain array. Then you can create a node as follows:

    function YOUR_MODULE_domain_insert($domain, $form_values = array()) {
    $domain_id = $domain['domain_id'];
    
    $node = new stdClass();
    $node->type = 'your_type';
    $node->title = 'Your Title';
    node_object_prepare($node);
    $node->language = LANGUAGE_NONE;
    $node->domain_site = 0;
    $node->domains[$domain_id] = $domain_id;
    
    $node = node_submit($node);
    node_save($node);
    }