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.
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
Comment | File | Size | Author |
---|---|---|---|
#6 | feedapi_mapper_email.patch | 2.1 KB | gionnibgud |
#5 | feedapi_mapper_email.inc_.txt | 1.9 KB | gionnibgud |
#3 | feedapi_mapper_email.inc_.txt | 1.89 KB | gionnibgud |
Comments
Comment #1
alex_b CreditAttribution: alex_b commentedGreat work. If I get a proper patch for this and a thumbs up by a tester, I'll commit this to 6.x
Comment #2
alex_b CreditAttribution: alex_b commentedI'd call this a "patch that needs work" :)
Comment #3
gionnibgud CreditAttribution: gionnibgud commentedI forgot to upload the file.
Comment #4
alex_b CreditAttribution: alex_b commentedGreat.
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.
Comment #5
gionnibgud CreditAttribution: gionnibgud commentedNot familiar with csv and patches so here is the file.
Same as #comment-1217140 but with the // $Id$.
Comment #6
gionnibgud CreditAttribution: gionnibgud commentedA patch, my first try.
Comment #7
scottrigbyHi gionnibgud,
Great work :) This patch works like a charm.
Comment #8
gionnibgud CreditAttribution: gionnibgud commentedI'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'.
Comment #9
SocialNicheGuru CreditAttribution: SocialNicheGuru commentedi 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
Comment #10
alex_b CreditAttribution: alex_b commentedThis mapper is not compatible with latest API changes (see api.php in 6.x-dev).
Comment #11
BenK CreditAttribution: BenK commentedSubscribing...