When creating a node programmatically, what is the way to assign node to all affiliates and be owned by the primary domain?

Comments

agentrickard’s picture


$node->domain_site = TRUE;
$node->domains = array(-1 => -1);

The -1 is because you can't use 0 with checkboxes. This piece of hilarity was removed from 7.x.3, so there you do this:

$id = domain_default_id();
$node->domain_site = TRUE;
$node->domains = array($id => $id);

See domain_node_access_records() for the save logic.

rangi500’s picture

@agentrickard Thanks for your comment, it helped me figure this out. Here's how I'm saving my nodes. The comments explain which parts of the node edit form each of the node properties relate to.

// Set domain access:
$node->domain_site = FALSE; // Sets "Send to all affiliates" off
$node->domain_source = $domain_id; // Sets the "Source domain"
$node->domains = array($domain_id => $domain_id); // Sets the domains node is published to.

// Save node:
node_save($node);

agentrickard’s picture

Issue summary: View changes
Status: Active » Closed (works as designed)