Field Collection to Easily Re-use Drupal Fields
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.
- Add a field of the type “Field collection”.
#3. Set up the Field collection fields
- Go to Structure > Field collections.
- You’ll see the field that you created.
- Click manage fields.
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.
In this example, I’m going to add three image fields:
#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:
#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:
Thanks Steve this is really a good favor from you. You made it easy to learn.
No problem, happy to help Shamoona. This is one module that’s fairly easy … once you know how.
Why put them in a field collection when the fields are reusable by themselves?
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.
Prepare to kill your site’s performance when you’re using field collections!
Thanks Tim. Can you explain more about the impact on your site(s)?
[url=https://drupal.org/project/multifield]https://drupal.org/project/…[/url]
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.
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]
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.
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?
Hi Umair,
Try the profile2 module that allows you customize the user profile.
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.
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
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?