Hi I've been doing some tests with this module and I tried to import cck email fields.
I copied the feedapi_mapper_link.inc and changed it to feedapi_mapper_email.inc.

Here's the code:




/**
 * On behalf implementation of hook_feedapi_mapper for email.module (CCK).
 * Email field module available at http://drupal.org/project/email
 * based on feedapi_mapper_link and feedapi_mapper_content.inc
 *
 * @param string $op
 * @param Drupal node $node
 * @param string $field_name
 * @param string, number or array of string or number $feed_element
 * @param string or number as id $sub_field
 *
 */
function email_feedapi_mapper($op, $node, $field_name, $feed_element = array(), $sub_field = '') {
  // Test for the node field that we would like to map to.
  if (strpos($field_name, 'field_') === 0) {
    if ($op == 'describe') {
      if (feedapi_mapper_content_is_cck_type($field_name, array('email'))) {
        return t('Maps an e-mail address to this e-mail CCK field.');
      }
      // Describe what we are doing in this mapper. This shows up as help text on the mapping page.
    }
    else if ($op == 'list') {
      if (feedapi_mapper_content_is_cck_type($field_name, array('email'))) {
        return TRUE;
      }
      // Here we are being asked to list sub fields we would like to map to.
      // In this case, we only map to the CCK field or not, so we return just TRUE.
      return FALSE;
    }
    else if ($op == 'map') {
      // Here is where the actual mapping happens.
      // When we are called at this point, $field_name contains the name of the field the user has
      // decided to map to and $field_element is the feed item element the user has decided to map.
      // We just need to put the two things together. The data structure here depends a lot on
      // CCK. We stick the value in $feed_element into $node->$field_name[0]['value'].
      if (!is_array($feed_element)) {
        $field = $node->$field_name;
        $field[0]['email'] = valid_email_address($feed_element) ? $feed_element : NULL;
        $node->$field_name = $field;
        return $node;
      }
    }
  }
}

I just did some quick checks so beware...

cheers

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alex_b’s picture

Great work. If I get a proper patch for this and a thumbs up by a tester, I'll commit this to 6.x

alex_b’s picture

Status: Active » Needs work

I'd call this a "patch that needs work" :)

gionnibgud’s picture

I forgot to upload the file.

alex_b’s picture

Great.

nitty:

Add // $Id$ to the second line.

Optional:

If you'd like to create a real patch, use *cvsdo add mappers/feedapi_mapper_email.inc* followed by cvs diff mappers/feedapi_mapper_email.inc > 363240_feedapi_mapper_email.patch

You have to use cvsdo ( http://durak.org/sean/pubs/software/cvsbook/cvsdo.html ) because cvs won't let you cvs add if you don't have write permissions to the repository :(

This is just FYI, I would also accept the plain .inc file.

gionnibgud’s picture

Not familiar with csv and patches so here is the file.
Same as #comment-1217140 but with the // $Id$.

gionnibgud’s picture

A patch, my first try.

scottrigby’s picture

Status: Needs work » Needs review

Hi gionnibgud,
Great work :) This patch works like a charm.

gionnibgud’s picture

Status: Needs review » Reviewed & tested by the community

I'm glad to hear that it did work.
I've been testing this mapper by doing a few big (but not huge )imports and i think it works all right.
I'm changing status to 'reviewed & tested'.

SocialNicheGuru’s picture

i get this error when i apply the patch

warning: Missing argument 3 for email_feedapi_mapper() in /drupal/sites/all/modules/feedapi_mapper/mappers/feedapi_mapper_email.inc on line 16

alex_b’s picture

Status: Reviewed & tested by the community » Needs work

This mapper is not compatible with latest API changes (see api.php in 6.x-dev).

BenK’s picture

Subscribing...