Is there a module which creates a field where you can choose the field type of the key and also the value during content type creation?


You can use the Field Collection module to achieve that functionality:

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

A field collection is internally represented as an entity, which is embedded in the host entity. Thus, if desired field collections may be viewed and edited separately too.

The idea is:

  1. Create a Field Collection.
  2. Add key/value fields to it with the field types of your choice.
  3. Add a Field Collection field to the content type you want these key/value fields on.
  4. Set the source of that Field Collection field to the new Field Collection you've just created.
  5. Repeat for whatever other content types you need to.
  • Thanks, I've always tried to avoid the field collection because it creates an actual entity from the fields. It's a shame you can't group fields without doing this. – user3791372 Nov 14 '14 at 12:31
  • Yeah Field Collection is a weird one (I try to avoid it to wherever possible), but short of writing your own field type I think it's the simplest way to get what you're looking for – Clive Nov 15 '14 at 17:13
  • As an update to this - if you're looking to create nodes programmatically, I'd certainly recommend you avoid this module - use entity reference and views and a separate content type. (EVA allows you to embed views as a field) I just found out the hard way that field collection isn't the best solution to this problem! – user3791372 Nov 16 '14 at 22:36
  • And furthermore, if you want 0 instances of your field collection (that is, allow optional instances of your field collection to be specified), it seems you can't – user3791372 Nov 17 '14 at 17:50

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.