You are here

function domain_node_load in Domain Access 7.2

Same name and namespace in other branches
  1. 7.3 domain.module \domain_node_load()

Implements hook_node_load()

File

./domain.module, line 1408
Core module functions for the Domain Access suite.

Code

function domain_node_load($nodes, $types) {

  // Get the domain data.
  $domains = domain_get_node_domains($nodes);
  foreach ($nodes as $node) {

    // Cannot load if the node has not been created yet.
    if (!isset($node->nid)) {
      continue;
    }

    // Append the domain grants to the node for editing.
    $nodes[$node->nid]->domains = isset($domains[$node->nid]['domain_id']) ? $domains[$node->nid]['domain_id'] : array();

    // If the node is not assigned, grant to all domains to prevent errors.
    $nodes[$node->nid]->domain_site = isset($domains[$node->nid]['domain_site']) ? $domains[$node->nid]['domain_site'] : variable_get('domain_behavior', DOMAIN_INSTALL_RULE);
    $nodes[$node->nid]->subdomains = array();
    if (!empty($nodes[$node->nid]->domain_site)) {
      $nodes[$node->nid]->subdomains[] = t('All affiliates');
    }
    if (!empty($nodes[$node->nid]->domains)) {
      foreach ($nodes[$node->nid]->domains as $gid) {

        // Domain 0 is loaded as -1 for use in forms.
        $gid == -1 ? $key = 0 : ($key = $gid);
        $domain = domain_lookup($key);
        $nodes[$node->nid]->subdomains[] = $domain['sitename'];
      }
    }
    else {
      $nodes[$node->nid]->subdomains[] = t('This node is not assigned to a domain.');
    }
  }
}