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?
1 Answer
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:
- Create a Field Collection.
- Add key/value fields to it with the field types of your choice.
- Add a Field Collection field to the content type you want these key/value fields on.
- Set the source of that Field Collection field to the new Field Collection you've just created.
- 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. Commented Nov 14, 2014 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 ♦Commented Nov 15, 2014 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! Commented Nov 16, 2014 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 Commented Nov 17, 2014 at 17:50