Feeds and Domain Access
Last updated on
13 July 2017
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
Domain Access fields do not appear to be mapped correctly. The following code can be used to update the imported nodes with the FeedImporters node settings. Note the special logic required to support Domain Sources module as this node property defaults to a domain if it is not set.
/**
* Implements of hook_node_presave().
*/
function MYMODULE_node_presave($node) {
static $domain_sources = array();
if (!empty($node->feeds_item->feed_nid)) {
if ($feed_node = node_load($node->feeds_item->feed_nid)) {
// Update the domain source.
if (module_exists('domain_source')) {
// We can not use $feed_node->domain_source as this is defaulted to the
// current site if not set. So we do a manual lookup.
if (isset($domain_sources[$feed_node->nid])) {
$domain_source = $domain_sources[$feed_node->nid];
}
else {
// This is to update existing nodes if they were incorrectly imported.
$domain_source = db_select('domain_source', 'ds')->fields('ds', array('domain_id'))->condition('nid', $feed_node->nid)->execute()->fetchField();
$domain_sources[$feed_node->nid] = $domain_source;
}
if ($domain_source) {
$node->domain_source = $domain_source;
}
elseif (!empty($node->nid)) {
// Manually delete as an empty $node->domain_source is not processed.
domain_source_node_delete($node);
}
}
// Assign the domain of the feed node to the feed entry.
$properties = array('domain_site', 'domains');
foreach ($properties as $property) {
if (property_exists($feed_node, $property)) {
$node->{$property} = $feed_node->{$property};
}
}
}
}
}
Help improve this page
Page status: No known problems
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion