Experimental project

This is a sandbox project, which contains experimental code for developer use only.

Patches welcome!

CSV to Fields will import field structure from a csv spreadsheet. A number of existing column handlers exist and it is trivial (imho) to write a custom one for your needs. Currently this module supports the following columns:

  • field_name: The machine name of a field.
  • type: The type of field (list_text, datetime, text_long, number_float, etc).
  • label: The display label.
  • cardinality: The number of values allowed. Use -1 or any string that starts with 'inf' (not case-sensitive) to indicate unlimited values.
  • allowed_values: A comma-separated list of possible values for list_* types.
  • description: Field help text.
  • default_value: The default value of a field.
  • required: Whether the field is required. Leave empty or 0 (zero) for not required, put anything else for required.
  • widget_type: If filled in, this will select a widget type other than the default for the type.
  • settings_text_processing: Whether a text_long field should be plain or filterable. Leave empty or 0 (zero) for not plain, put anything else for filtered. (Alias: filter_text)
  • settings_prefix: The prefix for a field. (Alias: prefix)
  • settings_suffix: The suffix for a field. (Alias: suffix)

Also, these column headers can be added for group support. Be sure to install the field_groups module first.

  • field_group_name: If not empty, this element will be converted into a group instead of a field. This should be the machine name of the group.
  • field_group_parent: If not empty, this field or group will be placed inside the given group. The group must have been defined already, or it must be in a higher row in the csv file than the element being placed inside it. Groups may be nested.

Columns can be in any order, and you can indicate which row is the header row with the `--header-row=1` option (in this case the header row is row 1).


Please back up your database before importing your csv. This process can't be easily re-run if something goes wrong.
Use the command `drush c2f ` to import. For example, if you want to import fields onto a node page, you would use `drush c2f node page `. For more options, including only using a subset of the spreadsheet, run `drush help cf2`.

Attached is a spreadsheet you can use to get started.

Writing new handlers

New handlers in D7 are called using 'drupal_alter'. The format for writing these depends on what you want to do with a given column header. If the column is used when creating a new field (such as the machine name, cardinality, and field type), then use the syntax: hook_csv2fields_field_base__alter. If the column is used when creating a field instance (labels, description, etc), then use the syntax: hook_csv2fields_field_instance__alter. And if the column is used when creating a new group, use the syntax hook_csv2fields_group__alter. You can write multiple handlers for the same header.


The module works as is, but the roadmap for this project includes at least the following: Drupal 8 support, feeds integration, and the ability to update as well as create entity fields.

Supporting organizations: 

Project Information