| Drupal

Drupal Field CollectionAs with so many of the tutorials we write, this tutorial started as a question in our support forums.

One of our members wanted to set up three image fields and then re-use them across multiple content types.

Our solution was to recommend the Field Collection module.

Field Collection allows you (as the name implies) to collect some fields together into a group. You can then re-use those fields for multiple content types, users, comments or really whenever you add fields.

Here's how to use the Field Collection module.

#1. Set up the modules

Field Collection requires that you install just two modules:

Enable those two modules.

#2. Add a Field Collection field

  • Go to Structure > Content types.
media_1376440684887.png
  • Add a field of the type "Field collection".
media_1376440772627.png

#3. Set up the Field collection fields

  • Go to Structure > Field collections.
  • You'll see the field that you created.
  • Click manage fields.
media_1376440824630.png

You'll now see an area very similar to your content type screen. Essentially your "field collection" is an entity that you can add fields to. If you're not sure what an entity is, read our introduction to Entites.

media_1376440843435.png

In this example, I'm going to add three image fields:

media_1376440921328.png

#4. Use the fields

Back in Step #2, you added the field collection to a content type. Click "Add content" and you'll find your reusable images are attached to the content and ready to use:

media_1376440953907.png

#5. Re-use the Field collection

Now that your Field collection is ready, you can use it with any other entity on your site.

You can use the whole Field collection or individual fields within the Field collection:

media_1376441777572.png

About the author

Steve is the founder of OSTraining. Originally from the UK, he now lives in Sarasota in the USA. Steve's work straddles the line between teaching and web development.