Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When creating a node programmatically, what is the way to assign node to all affiliates and be owned by the primary domain?
Comments
Comment #1
agentrickardThe -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:
See
domain_node_access_records()
for the save logic.Comment #2
rangi500 CreditAttribution: rangi500 commented@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);
Comment #3
agentrickard