Blog: Feed Element Mapper
Drupal Therapy: Learn How To Pull Blip.tv Video into Drupal
Use FeedAPI, Feed Element Mapper, and Embedded Media Field to Aggregate Video from Blip.tv
Use FeedAPI, Feed Element Mapper, and Embedded Media Field to Aggregate Video from Blip.tv
Sean Effel from Drupal Therapy just put up a wonderful screencast on how to pull blip.tv videos from RSS feeds into Drupal. In the screencast, Sean shows step by step how to set up your Drupal site with the FeedAPI, Feed Element Mapper, and Embedded Media Field modules to aggregate video feeds from blip.tv.
If you're interested in pulling video into your website or online app, you'll definitely want to check this out.
Build Your Own Mapper with the Feed Element Mapper
How To Create A Mapper
How To Create A Mapper
For those of you who after reading my last post on the Feed Element Mapper are now interested in the actual works of the module, below is a step by step guide on how to build your own mapper.
But first, three things needed to happen before we were able to create the map-any-element-to-CCK feature:
- Jess from WETA poked me about it for their TV and Radio feeds at the Drupal Meetup in DC on Tuesday :)
- FeedAPI's parser_simplepie now passes on the raw feed item, and with that anything it detects on the feed, on feed_item->options->raw
- Feed Element Mapper offers a generic CCK mapper
From those three, the one I would like to explain a bit better is the third because it shows how easy it is to write your own mapper so you can map any feed item element identified by FeedAPI to virtually any property of a node. Let me explain how I built this mapper:
1)
This is the empty implementation of hook_feedapi_mapper(). It's just sitting there and doing nothing. In this case, it' the implementation for the content module, the hook starts with content_.
function content_feedapi_mapper($op, $node, $field_name,
$feed_element = array(), $sub_field = '') {
}
- $op tells us which operation is being executed ('describe', 'list,' or 'map').
- $node is the node object we're operating on.
- $field_name is the name of the field on the node we are being called with (e. g. 'field_severity' for $node->field_severity, or 'taxonomy' for $node->taxonomy).
- $feed_element is only set on $op == 'map' and contains the exact element that has been mapped to the given field. This element can be a string, a number or an array of string or numbers.
- $sub_field is advanced stuff - it contains a value only if you offer more than one mapping target on $op == 'list', which we won't do here (e. g. a taxonomy mapper offering a mapping for each vocabulary).
Pick It Off the Feed, Stick It on the Node: Part 2
Use the Feed Element Mapper to Map Any RSS Tag to Taxonomy or CCK Fields
Use the Feed Element Mapper to Map Any RSS Tag to Taxonomy or CCK Fields
The first time I talked here about the Feed Element Mapper, it was still quite basic - it just mapped feed elements recognized by FeedAPI to taxonomy terms. That was already pretty cool, but what about mapping to CCK fields, and what about mapping any tag - even custom ones - to CCK fields?
Well, the latest developer version of FeedAPI (Jan 23rd), together with Feed Element Mapper 1.0 beta 3, can do this. It offers a straight forward form manageable also for the not so experienced site builder. I recorded this screencast to show you how this plays out on the UI:
If you would like to try this, take care that you do the following:
- Use FeedAPI 1.0
- Use Feed Element Mapper >= 1.0 beta 3
- Configure your feeds to use parser_simplepie as parser.
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;
}
}



