Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Feeds cheatsheet for developers

Parent Feed: 

In this article I would like to create some notes about architecture of the Feeds module. This is really great module and it is real “must know” when we are talking about regular import of the data from some sources.

There is great documentation available on http://drupal.org/documentation/modules/feeds. Here I try to create a cheatsheet for 7.x version of the module that let developers brief understanding about how things work.

Diagram is clickable

More detailed explanation

FeedsSource object that contains settings of the source.

FeedsFetcher fetch() method should retrieve content of the feed that has been fetched (for example long string received from URL) FeedsFetcherResult object is created from this content (it is located in raw property) and passed to FeedsParser.

FeedsParser parse() method parse the raw content of the FeedsFetcherResult object and creates array of the items. FeedsParserResult object is created from these items and passed further to FeedsProcessor. Also it is very important to define mapping sources in method getMappingSources so your items fields will be visible in mapping.

FeedsProcessor process() this is where target entities got created. The idea is that we iterate through all items passed to us in FeedsParserResult, check the hashes of each item (in order to not reimport data that hasn't changed), map the fields (using map() method) and save target entities (using newEntity() or entitySave()).

As you might notice we also pass FeedsSource to each of above mentioned methods. This is needed for tracking the progress of the batch operations.

One of my last tasks I had was to import some data from external source that has REST interface. Only things I needed to implement was to write FeedsFetcher plugin where in fetch() method I did REST calls to my application. And I needed to implement FeedsParser where I did some manipulations with data and defined mapping sources.

Hope this cheatsheet will be handful for new people trying to use feeds and developers who already used feeds to remind the internal architecture.

Diagram has been created with Dia v0.97.1

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web