Secondary menu

Field Cardinality Overridden in Features

nrussell's picture

Field Cardinality Overridden in Features

Written by Nick Russell on

The Scenario

  1. Create a content type A with some custom fields on it.
  2. Export the new content type as a feature, including the Field Bases and Field Instances for it. We call it Feature A.
  3. Create another content type B with custom fields on it. Some of these custom fields are reused from the previously defined fields in content type A, while others are new to this content type. For the fields you are reusing from content type A, change the cardinality (Number of values) if applicable to the field.
  4. Export the new content type as a feature, including the Field Bases and Field instances for it. We call it Feature B.

Crap! What just happened?!

If you performed the above steps, you'll notice that your new content type B changes has caused your Feature A feature to change into an overridden state. But why? Aren't they different? Sure you reused some fields, but doesn't CCK allow for the creation of Field Instances (or copies of already created fields)?

Yes, it does, but not for all settings on a field, in particular, cardinality. If you take a look in the database table field_config, you'll notice there are a handful of rows in it. One of the rows in the table is called "cardinality". This is the value that defines whether a field can be added X number times to an entity it is applied to. Its a setting that is controlled in the Base Field definition for the field.

What Next?

Stop trying to figure out why your features that contain the base field definition constantly get overridden. Create a new field if the cardinality needs to be different from any other fields that do the same thing or perform the same functionality. Currently, its the only way to work around this if your running a heavily driven features site.

I would be awesome if we were able to create new copies or instances of fields and provide these settings as unique to the field instances, but currently this is not how it works. Mike Potter put together a nice writeup of some of the changes made to Features in regards to Field Bases and Field Instances inside of features and the reasons behind the changes: http://www.phase2technology.com/blog/new-field-bases-and-instances-in-features/