Field collection

Overview

The Field Collection module is the successor to the CCK3 Multigroup. It allows a set of fields to be combined together and treated as a single field. For example, a field collection named Playlist can be created consisting of the text fields Song and Artist. When a Playlist entry is created the Song and Artist fields are presented together as elements of the Playlist field.

Usage

When the Field Collection module is installed a new Field type named 'field collection' becomes available in the Manage fields tab of supported entities. In a basic Drupal installation these are:

  • Content types
    e.g. Home > Administration > Structure > Content types > Basic page > Manage fields
  • People/Accounts
    Home > Administration > Configuration > People > Account settings > Manage fields
  • Taxonomy
    e.g. Home > Administration > Structure > Taxonomy > Tags > Manage fields

Manage or adding a field collections

After the field collection field is created it's managed under from Home > Administration > Structure > Field collections. This is where fields are added to the field collections created in the Manage fields tab.

There is one permission, Administer field collections. It allows the holder to create and delete fields on field collections.

Example Usage

Make sure both the Field Collection and Field UI modules are enabled to follow this tutorial.

You are creating music playlists, which consists of multiple songs. Each song has a specific song name and artist.

  • Go to admin/structure/types/add. Create a new content type: Playlist
  • Add a new field to it: Track
    • type: Field collection
    • widget: Embedded
    • number of values: Unlimited)
  • Go to admin/structure/field-collections and click on "Manage fields" for the created Track field
  • Add two fields to it: Song, Artist (type Text)

When you now add a new node of type "Playlist" you can add as many tracks to it as you like.

Example: Altering the structure of field collection items

For the purpose of displaying the links from the field collection view field formatter at the top instead of the bottom here a little

Example: Programmatically adding field collection entries into a existing field collection parent item

Some times we find ourselves with Field Collection that have other Field Collection as childs and we need to add data to those child fields

Example: Programmatically adding field collection entries to a Profile2 profile

The Drupal 7 Profile2 module is the successor to the Drupal 6 core profile module. Profiles created with Profile2 are entities and can

Example: Programmatically adding field collection entries to a node

In this example a function adds an entry to a node with a field collection named field_activity_log.

Example: Programmatically create and update field collection with Entity API

The Entity API provides classes and methods / functions that make CRUD for entities much, much easier and less prone to errors and bugs.

Example: Using Field Collection to force a list of human-readable names of documents attached to a node

Overview

Import field collection using feeds (And example use case)

You need install http://drupal.org/project/field_collection_feeds. Here is an example how to use it:

Understanding Field Collection Values

When a field collection is added to a user, node, or other Drupal entity it is represented with a field type of field_collection_item. The

Guide maintainers

tim.plunkett's picture