Development Seed Blog
Pick It off the Feed, Stick It on the Node
FeedAPI Now Maps Feed Elements to Node Fields
FeedAPI Now Maps Feed Elements to Node Fields
Last week I did some cleaning up of the soon-to-come FeedAPI beta release. I got fired up and decided to address one of the more exciting feature requests for Drupal aggregators - a feed element mapper. This feature will make it possible to freely map elements on feed items to fields on nodes that are created from these feed items.
The feed element mapper is an add on module for FeedAPI. It's currently in a proof of concept state and therefore lives in my sandbox. This screencast shows a demo of the straightforward mapping process.
For the developers
At the moment it's only possible to map to taxonomy, although writing your own mapper should be easy. This example of the taxonomy mapper shows how you can define a feed element mapper for your node field. First your mapping function is asked which fields it exposes ($op == 'list'). Then, when the user defines a feed element for one of the fields you exposed, the function is called again with the mapped elements and the node to stick them onto ($op == 'map').
function feedapi_mapper_map_taxonomy($op = 'map', $node, $feed_element = array(), $sub_field = '') {
if ($op == 'list') {
if ($vocabularies = taxonomy_get_vocabularies($node->type)) {
foreach ($vocabularies as $v) {
$sub_fields[$v->vid] = $v->name;
}
return $sub_fields;
}
return FALSE;
}
else if ($op == 'map') {
if (is_string($feed_element)) {
$feed_element = array($feed_element);
}
if (is_array($feed_element)) {
if (!is_array($node->taxonomy)) {
$node->taxonomy = array();
}
$node->taxonomy = array_merge($node->taxonomy, _feedapi_mapper_create_terms($feed_element, $sub_field));
}
return $node;
}
}

Comments
Drupal rocks
Cool feature, we´ve just went online with a bigger Drupal-Project and looking forward to include a blog. We´re just exploring the abilitys of Drupal.. I think this nice feature will be helpfull!
This is great work. I'm
This is great work. I'm looking forward to updating a couple test sites and seeing what can be done.
Barton
Nice nice really nice
Every day that passes just makes me feel more and more grateful that I decided to take the time and move to Drupal from Joomla. Suchmaschinenoptimierung
Annem Dizisi
God bless Drupal
Every day that passes just makes me feel more and more grateful that I decided to take the time and move to Drupal from Joomla. The FeedAPI is one of the best things to drupal since sliced bread I tell ya.
FeedAPI
I had an issue with FeedAPI wanting an array where I was giving it an object (I isolated the error as happening at return $node; and commenting that line out made the error disappear, and my .inc file is structurally the same as the taxonomy .inc file).
Hi - please report this
Hi - please report this issue at http://drupal.org/project/issues/feedapi - thank you.
Not possible *at the
Not possible *at the moment*, but I'm thinking that an admin only interface could be implemented quite easily? Not sure of the technicalities. I'm thinking of matching a user-added feed to a set of mapping rules via a comparison on the url?
Wow this would have saved me
Wow this would have saved me a lot of code about 6 months ago. It would be great if this could continue to be extended to handle things like multiple-value cck fields, nodereferences, imagefields, etc.
Hi Alex, Indeed, the number
Hi Alex,
Indeed, the number of supported fields is growing. Check out the issue queue of Feed Element Mapper to get an idea of what's stirring.
Alex
Drupal development tools
Thanks for the demo of the straightforward mapping process. I am just a student trying to learn more about Drupal. This blog gives me a lot of info, all most too much...;-)
Interesting. Is it possible
Interesting. Is it possible to make more than one mapper for a field at once?
Hi Cure, While you can
Hi Cure,
While you can define more than one mapper for a field you can't use more than one at a time. You can always write your custom mapper that does two things at once (by e. g. calling up the mappers you need to use at the same time).
do we ask supporting
do we ask supporting modules to maintain it with their code?
now
upgraded to FeedAPI 1.0 compatibility.
Great to see this come to life...
...hope you are seeing the same long term capabilities I am envisioning here.
I believe we can ship with additional mappers, one per field type. E.g. cck_textfield.inc
Is this close to a Data API? Or do we need to include all these mappers with FEMP directly? For instance, including CCK out of the box is a no brainer, but what about the "Link" field module, for instance? Do we include it with FEMP in a maps/ subdir? Or do we ask supporting modules to maintain it with their code?
Hi Boris, I envision this
Hi Boris,
I envision this coming together a lot like views module:
ship with an implementation for a couple of popular modules, have more exotic modules implement their own mapper, or even have them supplied by third party modules.
Feed Element Mapper supports all that.
Alex
Mapper upgraded to FeedAPI
Mapper upgraded to FeedAPI 1.0 compatibility.
I just posted a reply on the
I just posted a reply on the feature request that explains the concepts in the feed element mapper: http://drupal.org/node/165388#comment-330766
Post new comment