Composed Field form editing.
Composed Field node viewing
Field UI - Widget Form of a Composed Field

This project is not covered by Drupal’s security advisory policy.

Composed Field is an implementation of core's Field UI that allows you to split a single field into as many sub-fields as you like.

You can configure each sub-field types and attributes as they were literally a single field.
All the Form Controls are configurable through the Field Widget Form.

Features

  • Each sub-field element type can be individually set to:
    checkbox, checkboxes, date, fieldset, file, machine_name, managed_file, password, password_confirm, radio, radios, select, tableselect, text_format, textarea, textfield, vertical_tabs, weight.

  • The following field display settings are available:
    Unformatted list (default), Fieldset, HTML list, Table, Accordion, Tabs, Dialog

How does it work?

Each field stores its value as a serialized array into the database. Each array element represents the sub-field value.

For instance:
Say you have a field for collecting phone numbers, the phone number field element will have these sub-fields:

Landline/Mobile (select options) | Country Code (select options) | Area Code (select options) | Number (textfield)

The sub-field values will be lumped together into an array like this:

array(
  [1] => 'landline', // Landline / Mobile sub-field.
  [2] => '55', // Country code  sub-field.
  [3] => '66', // Area code  sub-field.
  [4] => '3521-5555', // Number  sub-field.
);

After that the array is serialized and stored into the database as a single value.

Similar Modules

  • Double Field is limited to 2 sub-fields only and each sub-field only supports textfield, select list, single checkbox and textarea types.

    Composed Fields supports an unlimited number of sub-fields and each sub-field can be set with any of the element types listed in Form Controls

  • The Field collection uses a different approach for creating composed fields. Here are the main differences between this module and the "Field Collection":

    The host field created by "Field Collection" is in fact an entity that gets attached to the fieldable entities (nodes, taxonomy, comment, commerce products, etc). So, although you attach a Field Collection through the Field UI, what is being attached is not a field but an entity.

    Once you get your new entity (host field) attached to your fieldable entity (node, comment, taxonomy, commerce product, etc) then you have to attach the fields ( what would be the subfields ) into the host field ( Field Collection entity).

    Each subfield is actually a field on its own, that is, from the database point of view, each subfield is a single field.

    "Composed Field" on the other hand attaches a field (host field), not an entity, to your fieldable entities (node, comment, taxonomy, commerce product, etc) through the Field UI. At the end of the day, even if you set a field with say 4 subfields, you will end up having only one field and a single value saved into the database.

    Unless you have a very specific use case need "Composed Field" should do what you need with less effort and less resources.

How to use

Once you enable this module you will have a new "Type of data to store" called Composed Field at the Field UI.

You should also give permission to trusted roles for entering PHP code into the sub-field attributes that requires it so for functioning, like for instance the #ajax callback function name.

Project information

Releases