Since there's no mapper, yet, for CCK or Domain Access, I worked around it. This is just to share what I did for people who need it right now and can't wait for a proper mapper. Once there are mappers for these, this code is not needed anymore.

/**
 * Implementation of hook_nodeapi().
 */
function YOURMODULE_nodeapi(&$node, $op) {
  switch ($op) {
    case 'presave':
      if ($node->type == 'YOUR_FEED_ITEM_NODE_TYPE') {
        if (!empty($node->feeds_node_item->feed_nid)) {
          $feed_node = node_load($node->feeds_node_item->feed_nid);
          
          // Assign the domain of the feed node to the feed entry.
          $node->domain_site = $feed_node->domain_site;
          $node->domains     = $feed_node->domains;
          $node->subdomains  = $feed_node->subdomains;          
          
          // Copy CCK field.
          $node->field_CCK_FIELD_NAME = $feed_node->field_CCK_FIELD_NAME;
        }
      }
      
      break;
    
   }
}

Note that this must be done in presave. I could not get it to work in insert. Thanks to awolfey for pointing me at presave. :)

Michelle

Comments

ehudash’s picture

testing...

ehudash’s picture

@Michelle,

It worked like a charm for me.
This was very helpful!

Thanks!

ultimike’s picture

Thanks for the code snippet - it works like a charm and is exactly what I was looking for!

-mike

alex_b’s picture

Status: Active » Fixed

I've added a link to this guide to the FAQs http://drupal.org/node/836618#comment-3718366

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dat deaf drupaler’s picture

Category: task » support

This is what I have been looking for. I apologize for being PHP illiterate.

I have created cck like this:

    -celebrity profile page (not actual user profile)
    -youtube video feed
    -youtube video item (embedded)
    -vimeo video feed
    -vimeo video item (embedded)

I need to reference each videos automatically to celebrity profile cck through feed importer (is this also called inheriting?)... am trying to avoid creating dummy user accounts in order to use user ID for mapping in node processor. Seems like I have no lucks with using taxonomy so far. I am unsure if OG would be the answer to what I am trying to achieve?

Where do I add the codes posted above and how do I implement it?

Your help would be very much appreciated!

mstrelan’s picture

Thank you so much Michelle, this is really helpful.

alan d.’s picture

For D7 Domain Access. Domain sources node_load() has some tricks to it.

/**
 * 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 {
          $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};
        }
      }
    }
  }
}
alan d.’s picture