Drupal 7: ¿Cómo puedo crear un campo clave / valor (o grupo de campos, si eso es posible)?

Let's say I'm creating some app documentation. In creating a content type for functions, I have a text field for name, a box for a general description, and a couple other basic things. Now I need something for storing arguments to the function. Ideally, I'd like to input these as key-value pairs, or just two related fields, which can then be repeated as many times as needed for the given function. But I can't find any way to accomplish this.

The closest I've gotten is an abandonded field multigroup module that says to wait for CCK3, which hasn't even produced an alpha yet as far as I can tell and whose project page makes no obvious mention of this multi-group functionality. I also checked the CCK issue queue and don't think I saw it in there, either.

Hay un corriente viable way of doing this I'm not seeing? Viable includes "you're thinking of this the wrong way and do X instead." I've considered using a "Long text and summary" field, but that smells hackish and I don't know if I'd be setting myself up for side-effects. I'm new to Drupal.

preguntado el 09 de enero de 11 a las 12:01

I know this is from ages ago, but I don't understand why you couldn't simply have used the list_text field type, and then entered the key value pairs as key|value, with each pair on its own line. -

3 Respuestas

Aquí debe visitar el http://drupal.org/project/field_collection module but it's not yet ready. Right now you would need to implement your entity alas to do this :( not easy.

Respondido el 09 de enero de 11 a las 15:01

Thanks. I hadn't seen this one. May not be quite usable yet, but it's something to watch. - Su'

Not sure how well it would work, because it currently does a bit more (eg, forces to group pairs into categories and the keys need to be predefined) but you might want to have a look at http://drupal.org/project/properties.

Respondido el 10 de enero de 11 a las 08:01

This is interesting, but for what I'm trying the keys do need to be ad hoc, unfortunately. - Su'

You could create a these key-value fields on their own: create 2 regular fields that that can be added as often as needed.

So you have a x fields for the keys and x for the values. If this is only for you or other people it might work OK but usability wise, it's very ugly.

If you need to extract the fields from the function, to display it properly in a page template, you should propably use a different approach. Write the function with its arguemnts in a CCK field and in the template extract them as needed. The arguments are always (depending on language) in () and the different arguments are seperated by , so splitting them would by pretty easy.

Respondido el 09 de enero de 11 a las 15:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.