Hello,

First of all - GREAT MODULE! I can't believe it took me so long to find it.

I have a question, though. I have 3 domains:

domain.com
one.domain.com
two.domain.com

I would like to achieve the following functionality:
1. When one publishes a new book_type content one one.domain.com, it will be published as well on domain.com, but not two.domain.com.
2. When one publishes a new book_type content one two.domain.com, it will be published as well on domain.com, but not one.domain.com (and so on for ALL the subdomains I will ever have - when somebody publishes on the domain, this content should be seen on that domain and the main domain, not other subdomains).
3. Nobody (except user 1, of course) should be allowed to publish book_type content on domain.com directly.

How can I achieve this functionality?

Comments

agentrickard’s picture

You have two options, both of which require custom code.

1) Use hook_form_alter() to auto-select the domains on the node form. This could be a little tricky, and it would allow users to change the settings.

2) Use hook_domainrecords() to always assign book_type nodes to the primary domain, which sounds like what you want. That would look something like so:

// This assumes you have a module named custom.module.
function custom_domainrecords(&$grants, $node) {
  global $_domain;
  // We only care about the book_type node.
  if ($node->type != 'book_type') {
    return;
  }
  $primary_set = FALSE;
  foreach ($grants as $key => $grant) {
    // Remove the domain_site grant.
    if ($grant['realm'] == 'domain_site') {
      unset($grants[$key]);
    }
    // Remove domains we don't want.
    else if ($grant['gid'] != $_domain['domain_id']) {
      unset($grants[$key]);
    }
    // Check that the primary domain is set.
    if ($grant['gid'] == 0 && $grant['realm'] == 'domain_id') {
      $primary_set = TRUE;
    }
  }
  // Make sure the primary domain is selected.
  if (!$primary_set) {
    $grants[] = array(
      'realm' => 'domain_id',
      'gid' => 0,
      'grant_view' => TRUE,
      'grant_update' => TRUE,
      'grant_delete' => TRUE,
      'priority' => 0,
    );
  }
}

You might have to do a combination of both. Note that your hook_form_alter() implementation must fire after domain_form_alter().

See API.php in the download for details on these hooks.

Eli Baskin’s picture

Unfortunately I am not a coder, and I have no idea even what file to edit. Furthermore, won't it be a problem when I update to the next version of Domain Access?

Eli Baskin’s picture

Hmm, I've read how to create a module - created my own module, installed it - but it doesn't work, no error messages and the main domain is not being added. Any idea what can be wrong?

agentrickard’s picture

Status: Active » Closed (works as designed)