I'm modifying the FeedAPI Inherit module to add http://drupal.org/node/233281 (Make feed item Inherit Domain Access info from feed). Everything else works, there's just one thing left to do - given two $node objects, what PHP code do I need to copy the Domain Access settings (i.e. which domains they're assigned to, and whether it's published to all affiliates) from the parent node to the other node? It seems this should be simple, but I'm struggling to find out how to do it. Thanks!

Comments

agentrickard’s picture

In the parent node object, there should be two elements:

$node->domain_site == BOOLEAN TRUE/FALSE
$node->domain == array() of active domains

The only trick is that $node->domain may have an element of -1, which is the default domain. We have to use -1 because FormsAPI checkboxes do not allow for a 0 to be passed as a value. So sometimes we have to convert the -1 to 0. You should not have to here.

See domain_node_access_records() to see how these values are handled. In that function, you can ignore the $node->domains_raw variable, which is only used for non-privileged users.

So you probably need something like this:

// Load the parent node.
$parent = node_load($nid_of_parent_node);

// Get the child node
$child = result_of_feed_api_function();

// Load the parent rules onto the child.
$child->domain_site = $parent->domain_site;
$child->domains = $parent->domains;

node_submit($child);
node_save($child);

That should be about it. node_save() will invoke the node access rules for you.

agentrickard’s picture

Status: Active » Closed (fixed)
Jomel’s picture

This works great, thanks. I'll submit a patch for FeedAPI Inherit soon...