9

I want to add a field to multiple content types at once, and configure it for all of them at once as well.

Reason being is that I have many content types, all of which need to be updated by adding this new field to each. This field will be configured the same for all of the content types as well. I have to repeat this process of adding and then configuring the field every content type I want to add it to, and it gets arduous after a while.

Is there any way to do a mass add/configure of a new field to many content types?

  • How many content types do you have ? – bobylapointe Nov 10 '13 at 17:04
  • I'm assuming this question is no longer relevant for OP, but is relevant for Nigel Waters who set the bounty. Would you Nigel care to comment? – Kari Kääriäinen Nov 10 '13 at 23:44
  • There are 25 (It is a very large site, that does require these to be separate content types). – Nigel Waters Nov 11 '13 at 15:03
  • Btw, another solution is to hire someone cheap for this kind of stuff :) – donquixote Nov 13 '13 at 20:00
  • Or a browser macro? – donquixote Nov 13 '13 at 20:00
9
+50

Broad lines using the Features module could be:

  1. Add the field to two (to see the pattern) content types by hand
  2. Create a Feature including field bases and field instances for the newly created fields
  3. Edit the created module multiplying the field bases and instances to all content types needed
  4. Enable the edited module
  • I don't remember how exactly features deals with fields.. is it possible to disable the feature after the fields have been created? – donquixote Nov 13 '13 at 18:33
  • The newborn module will depend on Features, so basically no, as far as I know. – Kari Kääriäinen Nov 13 '13 at 19:43
  • I mean disable the newborn module, not disable Features. The question is whether the field instances will still be there. Maybe Lester Peabody or Nigel Waters can give this a try and report back. – donquixote Nov 13 '13 at 19:46
  • Oh sorry. Yes, actually both can be disabled, the fields will live on in the database, I see, as I'm now testing it myself. – Kari Kääriäinen Nov 13 '13 at 19:56
  • This is the right answer for default drupal setups and most other drupal setups too. But if you have different display modes available for different content types, you are better off configuring the fields in each content type by hand, or make sure you use the correct display types in your field_instance array code. – Sumeet Pareek Jun 22 '15 at 16:28
5

Use the Field Tools module:

A collection of useful UI tools for working with fields:

Overview of fields with links to edit single instances, and all instances at once
Clone any field instance to multiple entities and bundles
Clone all field instance of a bundle to multiple entities and bundles
Import and export fields
Delete multiple instances of a field
Apply a vocabulary to multiple entities and bundles at once (the same way vocabularies were applied to content types on Drupal 6)
... your idea here. Patches welcome!
  • This sounds pretty awesome, I'm going to have to look at this. – Lester Peabody Dec 12 '13 at 15:31
3

If you don't mind writing a custom module for this, it's relatively easy to add a field to a content type via code:
$instance = array(
'field_name' => 'field_firstname',
'label' => 'First name',
'entity_type' => 'node',
'bundle' => 'person',
);
field_create_instance($instance);

The above code will add the field "field_firstname" to the content type with machine name "person". So you could create a module that a form that allows you to select a field and a number of content type and upon submission the field is added to all selected content types.

1

The few times that I've had to do this I've used Field Collection.

Provides a field-collection field, to which any number of fields can be attached.

It's still pretty arduous though, as you have to add the field collection field to every content type. That said, if you're adding 5 or 6 fields to multiple content types, you only have to configure the initial 5 or 6 fields once in the field collection.

Following that, you create the field collection field (for arguments sake let's call it field_collection_field) on one of your content types, and then re-use the same field on all the others.

As I said, you still have to configure one field on x amount of content types..but it's better than creating 10 fields on 10 content types (for example).

  • aah..sorry. I've just re-read your question as well and it only needs one field. Sorry for wasting your time >_< – Chapabu Oct 9 '12 at 15:25
  • That said you could put this one field into a field collection and configure it how you want, and then reference the field collection with your already configured field. However, this is a little overkill. – Chapabu Oct 9 '12 at 15:27
  • No problem Chapabu, this is still useful information going forward in case I need to do something like this down the road. – Lester Peabody Oct 9 '12 at 15:27
1

If you're comfortable manipulating the database directly, field instances are stored in the {field_config_instance} table. You can add/configure your field for one content type, then find the record in the database table and duplicate it.

You'll have to change two column values on the duplicated row:

  • id: Should be a new integer unique to the table
  • bundle: Should be the machine name of the new content type

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.