- In our example of a Visiting Lecturer content type, we want to have the flexibility of adding multiple dates, times, and locations to the content type. While we could just create a set number of fields, that can be cumbersome. Instead we can use Field Collections that will allow us to only have the number of fields that we need. Need to add another date, time, and location for the Visiting Lecturer? Just click on the Add another item in your completed content type, and you will have another collection of fields to fill out.
- To create a Field Collection, we need to do the following. Go to Add new field, update the Label (it is best to be descriptive if possible), select Field collection from the Field Type drop down menu, select Embedded in the Widget drop down menu, and finally, click Save.
- On the Field Settings tab, keep the Hide blank items checked and click Save field settings.
- You can then add some help text if needed and at the bottom, set the Number of values. What this value does is allow you to allow only a certain number of dates and locations added to your content type. For this exercise, we are setting it to unlimited.
- As you can see, the Date & Location field collection is just one line in our content type. How can we define the settings for the separate date and location fields? To do that we have to go to Field Collections by going to Structure -> Field Collections. Drupal treats them like their own separate content type. By adding the field collection in our content type like we did above, it will also add it to the Field Collections page for us to add to and edit.
Next: Field Collections: Date Field Type »