I wrote this for my site and thought I'd share it in case anyone else needs to do the same thing. I haven't done extensive testing but it seems to be working so far.

function cromods_nodeapi(&$node, $op) {
  switch ($op) {
    case 'insert':
      cromods_auto_assign_domains($node);
      break;
    
    case 'update':
      cromods_auto_assign_domains($node);
  }
}

function cromods_auto_assign_domains(&$node) {
  // Assign the node to all ancestors of the domain source.
  $tree = _domain_relationships_tree();
  $id = $node->domain_source;
  $ancestors = _domain_relationships_tree_get_ancestors($tree, $id);
  foreach ($ancestors as $ancestor) {
    $node->domains[$ancestor] = $ancestor;
  }
  
  // All nodes should end up on the main site.
  $node->domains[-1] = -1;
}

Michelle

Comments

michelle’s picture

Oh, I should mention that this code does not do any checking to see if the ancestors are active and that the user has permission to post to them because I have no need for that. If you have inactive domains or permissions for domains, you'll want to add that in.

Michelle

nonsie’s picture

Issue tags: +Needs documentation

Thanks Michelle! I really ought to write a handbook entry or a proper readme for this kind of stuff.

spike22’s picture

Hi!
Would you tell where this code goes into? Into the '.module' file? Also, a handbook or a 'readme' file for this module would be appreciated, because me and my friend can't figure out what it exactly does and how :) i think we need smtg like this module, but not sure.
thx in advance

michelle’s picture

It goes into your site's customizations module.

As for the rest, that's up to the maintainer. I don't use this module anymore.

Michelle

nonsie’s picture

Status: Active » Closed (works as designed)

I don't think this module needs a handbook entry since it only does one thing only. As stated on the project page "Domain Relationships module adds relationships/grouping capability for domains created with Domain Access module". Essentially it adds a parent (domain) field for each domain - what you do with it later is up to you. Michelle's use case for example adds selected domains' parent domain(s) to node's domain list (eg the domains the node is published to)

spike22’s picture

ok...thx for the replies!