Field Collection to Easily Re-use Drupal Fields

Drupal Field Collection

As 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

Author

  • Steve Burge

    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.

    View all posts
0 0 votes
Article Rating
Subscribe
Notify of
guest

15 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
shamoona
11 years ago

Thanks Steve this is really a good favor from you. You made it easy to learn.

steve
steve
11 years ago
Reply to  Shamoona

No problem, happy to help Shamoona. This is one module that’s fairly easy … once you know how.

Agnar Ødegård
Agnar Ødegård
11 years ago

Why put them in a field collection when the fields are reusable by themselves?

steve
steve
11 years ago

Hi Agnar. The main benefit is that you can re-use the fields with much greater consistency. You can be sure the field settings and display are the same whereever they’re used.

TimOnWeb
TimOnWeb
11 years ago

Prepare to kill your site’s performance when you’re using field collections!

steve
steve
11 years ago
Reply to  TimOnWeb

Thanks Tim. Can you explain more about the impact on your site(s)?

alex
alex
11 years ago
Reply to  steve

[url=https://drupal.org/project/multifield]https://drupal.org/project/…[/url]

Harv
Harv
11 years ago

Is there a similar module/plan to be able to share content between two completely different sites? ie. I have an event to add to a calendar on one site and want to add it to a second site, as well.

steve
steve
11 years ago
Reply to  Harv

Hi Harv. Yes, possibily, depending on how you want to do it. You could set up it up as simply as a RSS feed:
[url=http://www.ostraining.com/blog/drupal/aggregator/]http://www.ostraining.com/b…[/url]
[url=http://www.ostraining.com/blog/drupal/feeds/]http://www.ostraining.com/b…[/url]

ankit
ankit
9 years ago

Hello Steve, This is really good…But i have one doubt about how to add Color box with field collection field . I want use this inside view . Is their any way to configure the Color box with field collection field.

Umair
Umair
7 years ago

I want to override the edit profile page using panels, but the user field forms like username, password, email are not available. Only fields that I created and a General Form is available. What should I do?

Daniel Pickering
7 years ago
Reply to  Umair

Hi Umair,
Try the profile2 module that allows you customize the user profile.

Umair
Umair
7 years ago

Daniel,
I am sure you have understood. “User Profile” and “Edit Profile Page” are 2 different pages. “User Profile” is not an issue.
I came across this module sometime ago, but someone, at stackexchange or maybe other site, told me that it is not a good idea to use it to override. The problem is that the “Edit Profile Page” simply shows a long form. I want to divide it in vertical tabs with relevant fields. For example Email Tab will only have field form related to email settings. I thought I could use field_group module, but the problem was as I told above.

Daniel Pickering
7 years ago
Reply to  Umair

Hi Umair,
I see that would put you more in theming. Which can be quiet complicated have you done our course on theming? [url=https://www.ostraining.com/class/theming/]https://www.ostraining.com/…[/url]
Thanks

Daniel

Vivek
Vivek
5 years ago

But those field collections are rendered as html content in rest export instead of just the values and fields present in them. is there any fix for this issue?

15
0
Would love your thoughts, please comment.x
()
x