Skip to content Skip to navigation

Pulling Stanford Events into Drupal

Posted by: 
Topics: 
Tags: 

Pulling Events from events.stanford.edu (or any other iCal feed) into Your Drupal Site

Prerequisites

This tutorial assumes that you know how to:

  • Download and install Drupal modules
  • Configure permissions
  • Create custom content types using the CCK module
  • Enable and configure Views (the Views themselves, not just the module)

Download and Install Modules

The Advanced Help module provides instructions at help/date_api/ical-import

Create Two CCK Content Types

  1. Create a CCK content type ("Event")
    1. In addition to the standard fields, add a Date field and choose "Text field with Date Pop-up and Repeat options" as the input form element
      Screenshot of CCK date field settings
  2. Create another CCK content type (“iCal Feed”)
    1. This will be an "umbrella" content type for pulling in iCal feeds from any source
    2. On the content type creation screen, twirl open the FeedAPI fieldset
      1. Check "Is a field content type"
      2. Choose URL under "Supply feed as:"
      3. Check "Refresh feed on creation"
      4. Update existing feed items
        1. Check this if you want the information from the feed to override any local in-Drupal modifications to Events
        2. Uncheck this if you want to pull Events in via an iCal feed, then modify them within Drupal
      5. Minimum refresh period: The default (3 hours) is usually fine for this. Stanford Events only updates their feed every 8 hours (as of January, 2010), so if you are only pulling in from events.stanford.edu, you can set this to 8 hours.
      6. Delete news items older than: You can modify this setting to have Drupal clean up old Events that it has pulled in from a feed
        screenshot of FeedAPI fieldset settings
      7. Parser settings
        1. Choose the iCal parser
          Screenshot of iCal parser settings
      8. Processor settings->FeedAPI Nodes
        1. Check Enable. This will create new nodes (of the CCK type "Event") in your Drupal site based on the iCal feed that you provide below.
        2. Choose Event under Node type of feed items
        3. Input format for feed items should be set to Filtered HTML or Default format (if Filtered HTML is your default format). Choosing another format is not advisable, as it opens your site up to XSS attacks.
        4. Created date of item nodes: typically would be set to Retrieve from feed
        5. Duplicates: typically can be set to only within feed
          Screenshot of FeedAPI Node Processor settings
      9. Processor settings->FeedAPI Inherit
        1. We will not be using this feature in this example
  3. Note: Be sure to give yourself proper permissions to access all of the new fields and content types you have created.

Create an iCal Feed Node

  1. Now, create a new node of iCal Feed content type (at node/add/ical-feed)
    1. We'll be pulling events from the Stanford Open Source Lab, so we'll use "Open Source Lab Events" as our node title
    2. Feed fieldset
      1. Feed URL: Stanford Events publishes iCal feeds for organizations and categories. Right-click the iCal icon and choose copy link location. Paste that into the Feed URL field (e.g., http://events-prod.stanford.edu/byOrganization/993/eventlist.ics) screenshot showing location of iCal feed link on events.stanford.edu
      2. All other settings should inherited the defaults you set up when you created the iCal Feed content type. You can change these on a feed-by-feed basis if you wish.
      3. Save the node
  2. Now you need to map your feed items. Click the Map tab at the top of the node (next to View).
    1. Choose a source, choose a target, and click Add
      SourceTarget
      titleMap to Title (node)
      description Map to Body (node)
      options->VEVENT->DATE->DTSTART->datetimeMap to field_date (date): Start Date (date and time)
      options->VEVENT->DATE->DTEND->datetimeMap to field_Date (date): End Date (date and time)
    2. If you want to map additional fields, twirl open the Feed item example fieldset to see what the source fields look like
  3. Cross your fingers, then click Remove items (next to Map), and then click Refresh
    1. You can view the newly-created nodes at admin/content/node; verify that they have the correct title, body, and date/time

Note: Periodically, you may need to remove items and refresh.

Create the Calendar View

  1. Go to admin/build/views
  2. Scroll down past all of your active Views to the disabled Views. Find the calendar View (provided by the calendar module) and click Enable.
    Screenshot of the enable link for the calendar View
  3. This tutorial assumes that you know your way around the Views UI screen. As such, here are the relevant settings:
    Calendar Views Settings
    Section Option Setting Additional Information  
    Filters Node: Published Yes Provided by default  
    Filters Node: Type Event    
    Arguments Date: Date (node) Action to take if argument is not present: Provide default argument of type current date
    Granularity: Month
    Date field(s): Content: Event Date/Time (field_date) - From date
    Remove the default argument of Node: Updated date  
    Fields Node: Title   Provided by default  
    Fields Content: Event - From date   Remove the default Field of Node: Updated date  
  4. Save the view
  5. Go to /calendar (the default path of the calendar View) to view your calendar, um, "View"
  6. Celebrate!