Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Importing Data into an Address Field using Feeds

Video loading...

  • 0:01
    Mapping with Leaflet Importing Data into an Address Field using Feeds
  • 0:05
    with Amber Matz
  • 0:08
    In a previous lesson, we configured our location content
  • 0:11
    type to collect address data using Address Field module.
  • 0:15
    Then we brought in Geocoder module and configured
  • 0:17
    the geofield on our location content type
  • 0:20
    to use the data from the address field.
  • 0:23
    With Geocoder all set to transform that address data,
  • 0:26
    we are now ready to create some new location notes.
  • 0:30
    Since the process of geocoding addresses happens behind the scenes
  • 0:34
    when a new notice created or when a node is edited and saved,
  • 0:38
    it was important to do this configuration first,
  • 0:40
    before creating anymore location nodes to expedite data entry.
  • 0:45
    In this lesson, I'll walk through the process of importing
  • 0:48
    a comma-separated value text file, or CSV file, into a Drupal site
  • 0:53
    with address field using Feeds.
  • 0:56
    By the end of this lesson, you'll understand what data
  • 0:59
    you need to be sure and include in your CSV to avoid trouble
  • 1:03
    with Address field, how to configure a Feeds importer,
  • 1:07
    and how to configure the field mapping in the importer
  • 1:10
    with the somewhat esoteric field name that Address field provides.
  • 1:15
    There are a few things to keep in mind when preparing to import
  • 1:19
    addresses from a text file into nodes using Address field.
  • 1:23
    The first thing to know is that Address field uses universal terms
  • 1:27
    for structuring postal address data and, depending on what country's
  • 1:32
    terminology you are familiar with, the meanings of these terms
  • 1:36
    may not be immediately obvious.
  • 1:39
    For example, what does administrative area refer to?
  • 1:43
    Or locality-- the state, the city-- which is which?
  • 1:48
    On the Address Field project page at,
  • 1:54
    there is a glossary of terms.
  • 1:58
    From this glossary, we learn that "administrative area" refers
  • 2:02
    to state, province, or region and that "locality" refers
  • 2:06
    to a city or town, and that "thoroughfare"
  • 2:10
    refers to the street address.
  • 2:12
    These terms will be important to understand when we need to map
  • 2:16
    headings from a text file of address data
  • 2:20
    to fields provided by Address field, as we configure a Feeds importer
  • 2:25
    to create nodes using our location content type.
  • 2:29
    Additionally, according to the Documentation page, importing
  • 2:33
    Address field data with Feeds, which is node 1988472,
  • 2:40
    there are three important things to keep in mind with respect
  • 2:44
    to Address field data.
  • 2:46
    First, even if you know that all your addresses are in one country,
  • 2:51
    you must supply a value for country.
  • 2:54
    If your data doesn't already have a country,
  • 2:57
    then you should either add it to your text file
  • 2:59
    or use Feeds Tamper module to supply a default
  • 3:03
    value, such as the country all of your addresses are within.
  • 3:07
    The reason for this is that Address field uses the country value
  • 3:11
    to decide which address fields to display to you.
  • 3:15
    Address field will choke, if no value for country exists.
  • 3:19
    So you must either supply a default value or a real value
  • 3:24
    for each address in the text file containing your address data.
  • 3:28
    Second, the country value you supply must
  • 3:31
    be a valid two-character country code
  • 3:34
    that conforms to this ISO 3166-1 standard.
  • 3:40
    If you are using another format, such as the full name
  • 3:43
    of the country, you will either have to change your data in the source
  • 3:47
    text file or transform it during import using Feeds Tamper,
  • 3:52
    or through a custom module.
  • 3:55
    Finally, the data for state or province,
  • 3:58
    also known as "administrative area," must also use a two-digit code that
  • 4:04
    conforms to the ISO 3166-2 standard.
  • 4:09
    Once again, if your data doesn't conform to this,
  • 4:11
    you will want to change in the source file, if it's possible,
  • 4:15
    or use Feeds Tamper or custom module to update it accordingly
  • 4:20
    to prevent errors during import.
  • 4:23
    So let's take a quick look at the text
  • 4:25
    file I've created to make sure it conforms to these requirements.
  • 4:30
    I've located my branch location address CSV file.
  • 4:34
    And on a Mac, I'm going to right-click or Control-click
  • 4:40
    and I'm going to select Quick Look.
  • 4:43
    And this is going to give me a quick look of my CSV file.
  • 4:46
    And it's nicely organized into columns and headers,
  • 4:49
    so I can see what's going on here.
  • 4:51
    It's basically replacing all of the commas with rows and columns,
  • 4:56
    so it's a little easier to read.
  • 4:58
    So I'm going to check that I have a two-digit code in my State column,
  • 5:02
    which, it looks like, I do, and a two-digit code
  • 5:05
    in the Country column, which I also have.
  • 5:08
    So it looks like my text file is conforming to our basic standards.
  • 5:12
    And I'm not going to run into any gotchas
  • 5:14
    when I try and import this file.
  • 5:17
    So to create nodes using data from this text file,
  • 5:20
    we can use the Feeds module.
  • 5:22
    I'm going to hop over to the terminal.
  • 5:25
    And I'm going to use Drush to download feeds.
  • 5:27
    I'll type in drush dl feeds.
  • 5:31
    And Drush is going to download Feeds to my Sites All Modules directory.
  • 5:35
    And the Project Feeds contains four modules.
  • 5:39
    And two of them we're going to concern
  • 5:41
    ourselves with-- Feeds UI and Feeds.
  • 5:44
    The Feeds UI module is going to actually give us
  • 5:47
    an administrative screen and area to configure our Feeds Importer.
  • 5:53
    And it's possible to turn off the feeds UI, similar to how you can
  • 5:57
    turn off the Views UI, just in case you need to secure that and not
  • 6:03
    allow other users on your site to mess around with that configuration
  • 6:08
    once you have it set up.
  • 6:10
    So next, I'm going to enable the Feeds UI and the Feeds modules.
  • 6:15
    So I'm going to type drush en feeds ui.
  • 6:19
    And because Feed UI is dependent on Feeds, it will enable them both.
  • 6:24
    So I'll type y to continue.
  • 6:28
    Drush also lets me know that Feeds defines
  • 6:30
    the permission Administer Feeds.
  • 6:33
    So if there are other roles, other than your administrator role
  • 6:36
    that need this permission, you'll need
  • 6:39
    to go to the People section of your Drupal site
  • 6:42
    and make sure that the permission to Administer Feeds
  • 6:45
    is checked for the appropriate user roles.
  • 6:49
    All right, with Feeds and Feeds UI enabled, we can return to the site
  • 6:53
    and create an importer.
  • 6:55
    I'll navigate to Structure, Feeds, Importers.
  • 7:00
    And click the Add Importer link.
  • 7:03
    First, I'm going to give my importer a name.
  • 7:06
    I'll call it Locations Import.
  • 7:08
    And I'm going to give it a description of imports addresses
  • 7:13
    from a CSV file to create location nodes.
  • 7:16
    Then I'll click the Create button.
  • 7:18
    Now we have several different areas of configuration
  • 7:23
    that we need to go through.
  • 7:24
    And some of them we'll need to make changes in and some of them
  • 7:28
    we'll need to just leave them as is.
  • 7:30
    But we'll need to go through just about every section here
  • 7:32
    to make sure it's configured properly.
  • 7:35
    So first, in the left column, under Basic Settings,
  • 7:40
    I'll click the word Settings.
  • 7:42
    And I'm going to turn off the periodic import and click Save.
  • 7:49
    Next to the word Fetcher, I'll click Change.
  • 7:53
    And I'm going to change this from an HTTP fetcher, which downloads
  • 7:57
    content from a URL, which is why you might want to have
  • 8:00
    the periodic import on, but we are going to use a file upload.
  • 8:05
    And this file is pretty much going to be static for our purposes here.
  • 8:09
    So that's why we don't need the periodic import that we just
  • 8:12
    turned off in the previous setting.
  • 8:14
    So I'm going to select File Upload and then Save.
  • 8:19
    Next to Parser, I'll click Change.
  • 8:22
    And we need to change this from a common syndication parser
  • 8:26
    to a CSV parser.
  • 8:28
    So I'll click the Radio button next to the CSV Parser
  • 8:32
    and click the Save button.
  • 8:34
    It's important for each of these sections
  • 8:36
    that you click Save before you navigate to another one,
  • 8:39
    or else your settings won't be saved.
  • 8:43
    So this brings up the CSV Parser settings, which I'll click on.
  • 8:47
    And it just lets me know that the default delimiter is
  • 8:51
    a comma, which is what I have in my file.
  • 8:54
    But there are other delimiters available.
  • 8:57
    And you should select the one that is being used in your file
  • 9:02
    that you're using to import data.
  • 9:04
    So I'm going to keep this as comma.
  • 9:06
    And I do have my first row of my file
  • 9:09
    does have headers, so I'm going to keep this No Headers box unchecked.
  • 9:14
    And then I'll click Save.
  • 9:16
    Next to Processor, I'm just going to make sure
  • 9:19
    that the node processor is checked.
  • 9:21
    But you can see that out of the box, Feeds also
  • 9:23
    provides taxonomy term and user processors.
  • 9:27
    And then next to Node Processor in the left column,
  • 9:30
    I'll click Settings.
  • 9:32
    Now, here's where there is a required field.
  • 9:34
    And I need to select a bundle.
  • 9:37
    And a content type is a type of bundle.
  • 9:40
    So I'm going to select the location content type as my bundle.
  • 9:45
    It's possible for Feeds to update existing nodes.
  • 9:49
    So I'm going to go ahead and click Update Existing Nodes,
  • 9:54
    just in case we want to run the Importer more than once.
  • 9:58
    That way, it won't create duplicate notes.
  • 10:01
    If I was importing values into the Body Text field,
  • 10:04
    then I might want to change this text format from plain text.
  • 10:09
    But since it doesn't apply to this importer,
  • 10:12
    I'm just going to keep it as plain text.
  • 10:14
    Next, I need to select an author.
  • 10:17
    And I'm going to just choose a user on my system
  • 10:20
    that has permissions to create nodes of type location.
  • 10:25
    And I'm going to keep this Authorize box checked.
  • 10:28
    And I'm never going to expire the nodes.
  • 10:30
    If you were importing using an RSS feed or something else,
  • 10:33
    you might want to expire the nodes after a certain period of time.
  • 10:37
    But that doesn't apply to the situation.
  • 10:39
    Now, I'll click Save.
  • 10:41
    And then here we get to the meat of the Importer is the mapping.
  • 10:45
    So I've clicked Mapping in this Node Processor section.
  • 10:49
    And now with my CSV File close at hand,
  • 10:54
    I need to define a source and a target for each piece of data
  • 10:58
    that I want to import.
  • 11:01
    And it's very important that you get the source name exactly right.
  • 11:06
    It's case sensitive and typo sensitive.
  • 11:08
    So it's a really good idea to just simply copy and paste the header
  • 11:13
    from your text file into this field.
  • 11:15
    So that's exactly what I'm going to do.
  • 11:18
    So in my file, I've opened up my text file in Text Edit.
  • 11:23
    And I'm just going to copy and paste from this first row, which
  • 11:27
    contains my headers.
  • 11:28
    So the first piece of data I want to import is the branch name.
  • 11:33
    So I'm going to copy this into the Source field.
  • 11:39
    And then I'm going to select a target of the title.
  • 11:44
    And then I'll click Save.
  • 11:45
    And then I also want to import the branch name
  • 11:49
    as the postal address organization name.
  • 11:53
    So I'm going to create two targets for this one source.
  • 11:58
    Then I'll click Save.
  • 12:00
    One thing to keep in mind when creating these mappings
  • 12:03
    is that we need to have at least one row that is a unique target.
  • 12:08
    So for our import, I'm going to use the title as a unique target.
  • 12:12
    I'm going to click the gear and then I'm
  • 12:14
    going to check Unique and Update.
  • 12:18
    Then I'll save.
  • 12:19
    So now our branch name, which is mapped to our
  • 12:23
    no title is going to be a unique target.
  • 12:25
    And that's what Feeds is going to use to keep track of these nodes.
  • 12:29
    And if we run the Importer more than once, it will know what is unique.
  • 12:34
    Also, one thing to keep in mind with the Target fields
  • 12:37
    is that all of the fields that Address field provides
  • 12:41
    are pretended with postal address.
  • 12:44
    So that's how we'll know which fields
  • 12:46
    are provided by Address field.
  • 12:49
    Also, if you're having trouble understanding what these fields are
  • 12:53
    referring to, you can expand this Legend field set.
  • 12:58
    And it gives the name of the target and a description.
  • 13:01
    And that can be very helpful.
  • 13:04
    All right, continuing with our mapping, all copied.
  • 13:08
    The next header, which is address.
  • 13:11
    And I'll paste that into the source.
  • 13:14
    And I'll select the target of Postal Address Thoroughfare.
  • 13:20
    And click Save.
  • 13:21
    I'll copy the city.
  • 13:23
    I'll paste that into Source.
  • 13:25
    And I'll select Postal Address Locality as the target, then Save.
  • 13:33
    Next is State.
  • 13:34
    These are all US addresses, so I'm using State in my source file.
  • 13:39
    But in Address field, this is going to be Postal Address Administrative
  • 13:44
    Area, which would include provinces as well.
  • 13:47
    Then I'll click Save.
  • 13:48
    Next is the Zip or Postal Code, but I
  • 13:51
    need to use the exact header that I have in my CSV file.
  • 13:56
    I'll paste Zip into the source.
  • 13:58
    And then I'll select a target of Postal Address/ Postal Code,
  • 14:02
    then click Save.
  • 14:04
    And finally, the Country Code.
  • 14:06
    I'll select my header, which is Country.
  • 14:09
    And then a target of Postal Address, Country.
  • 14:13
    Now I'll click Save.
  • 14:16
    With my mapping complete, using the Bread Crumbs,
  • 14:19
    I'll return to the Feeds Importer's main page, which is where I can
  • 14:22
    find the link to actually run the Importer.
  • 14:25
    So your Importers will always be located
  • 14:28
    at whatever your base URL is slash import.
  • 14:32
    We only have one created now, so I'll
  • 14:34
    go ahead and click on Locations Import.
  • 14:36
    It lets me know the status of the import, if it's already been run.
  • 14:40
    You can delete items or unlock an import.
  • 14:44
    But since this is the first time we're importing it,
  • 14:47
    we can import it here and choose a file,
  • 14:49
    which we will do so in a second here.
  • 14:52
    If you have created your Feeds Importer before,
  • 14:55
    you've created your CSV file, or for some reason
  • 14:58
    you need to recreate your CSV file, you can download a template which
  • 15:03
    contains all the headers that have been defined as sources.
  • 15:07
    And we want to just double-check the delimiter as a comma.
  • 15:11
    And we do have header, so we want to leave the No Headers box unchecked.
  • 15:16
    So next, where I can choose my file.
  • 15:19
    And I'll go ahead and select that and Import.
  • 15:24
    Depending on how many records you have in your file
  • 15:28
    will determine how long this import is run.
  • 15:30
    And it can take quite some time, if you have lots and lots of records,
  • 15:34
    like hundreds or thousands.
  • 15:36
    So it looks like our Importer was successful.
  • 15:38
    We've created 22 nodes.
  • 15:40
    I'll click on the Find Content button.
  • 15:43
    And we can see all of our shiny new location nodes
  • 15:46
    that have been created.
  • 15:47
    If I choose one of these to view, you can see that our address data
  • 15:51
    has been imported, geocoded, and is now
  • 15:54
    displaying on a map using Leaflet.
  • 15:56
    In this lesson, we learned how to import address data to bulk
  • 16:00
    create location nodes using Feeds.
  • 16:03
    Specifically, we looked at importing address data contained in a text
  • 16:07
    file into specific fields provided by the Address Field module.
  • 16:12
    We configured a Feeds Importer with the appropriate settings that
  • 16:16
    ensured that the address data in the CSV file
  • 16:19
    was mapped to the proper fields on the Drupal site.
  • 16:23
    This address data was then geocoded, when the nodes were created,
  • 16:27
    because of the configuration we'd performed in the previous lesson.
  • 16:31
    As a result, all of our newly created nodes
  • 16:34
    using imported postal address data now
  • 16:36
    display that address location on a map using Leaflet.
  • 16:41
    Now that we have multiple location nodes,
  • 16:44
    we can explore creating a map that displays multiple locations on it.
  • 16:49
    In the next lesson, we'll explore the Leaflet Views module
  • 16:52
    and create an interactive map of multiple locations
  • 16:56
    using Leaflet and Views.
Loading ...

Importing Data into an Address Field using Feeds


n the previous lesson, we configured the location content type to collect address data using Address Field module. Then we brought in Geocoder module and configured the Geofield on our location content type to use the data from the Address Field. With Geocoder all set to transform that address data, we are now ready to create some new location nodes. Since the process of geocoding addresses happens behind the scenes when a new node is created or when a node is edited and saved, it was important to do this configuration first, before creating any more location nodes. To expedite data-entry, in this lesson, I'll walk through the process of importing a comma separated value text file or CSV file into a Drupal site with Address Field using Feeds.

By the end of this lesson, you'll understand what data you need to be sure and include in your CSV to avoid trouble with Address Field, how to configure a feeds importer, and how to configure the field mapping in the importer with the somewhat esoteric field names that Address Field provides.

Additional resources: