Posted by gionnibgud on January 23, 2009 at 5:13pm
| Project: | Feed Element Mapper |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
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:
<?php
/**
* On behalf implementation of hook_feedapi_mapper for email.module (CCK).
* Email field module available at <a href="http://drupal.org/project/email
" title="http://drupal.org/project/email
" rel="nofollow">http://drupal.org/project/email
</a> * 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
Comments
#1
Great work. If I get a proper patch for this and a thumbs up by a tester, I'll commit this to 6.x
#2
I'd call this a "patch that needs work" :)
#3
I forgot to upload the file.
#4
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.
#5
Not familiar with csv and patches so here is the file.
Same as #comment-1217140 but with the // $Id$.
#6
A patch, my first try.
#7
Hi gionnibgud,
Great work :) This patch works like a charm.
#8
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'.
#9
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
#10
This mapper is not compatible with latest API changes (see api.php in 6.x-dev).
#11
Subscribing...