Variable number of fields in a content type?

Topics: Writing modules
Jan 26, 2013 at 7:40 PM

I'm trying to build a content type that represents a travel package. Each travel package can have multiple hotels, a variable number, each including a picture and a description. I was thinking of having a travel package as a content type and then allowing hotels (possibly custom fields) to be added in the create Travel Package form. How do I make it possible to have multiple (and variable in number) fields inside a content item?

Thanks! 

Developer
Jan 26, 2013 at 7:46 PM

I don't think that's possible nor do I think that's the way to do it.

Instead, I would consider having a Hotel content type, so that you can instantiate and link as many Hotels as you need per Travel Package. If you don't want Hotel to be a content type, you could consider implementing it as a simple domain entity. And if you don't want to work with an extra table for Hotels, you could implement a sort of field that stores all the hotels in json or xml in that field as part of your TravelPackage form.

Question: When creating a TravelPackage, will the user be creating Hotels on the fly, or choose from existing ones? If the latter, you could probably use the ContentPickerField to associate existing Hotels with the TravelPackage.

Hope this helps.

Jan 26, 2013 at 8:05 PM
Edited Jan 26, 2013 at 8:09 PM

Thank you so much!!

 

I even thought of creating a hotel content type and using projections to display it!

The only issue is that the user will be creating hotels on the fly. So going to a separate page to create hotels (which only make sense in the context of a specific travel package) and then going back to the travel package creation page could be too much trouble…

Coordinator
Jan 26, 2013 at 9:56 PM

Spike, really ?

I see two solutions.

First you can simply use a content picker field which will let you select Hotels from your package.

Second solution is to use taxonomies, Hotels being one of them. Then you can select them from a package.

Developer
Jan 26, 2013 at 10:20 PM

Why are you so surprised that I give clever answers? :)

You see, that's exactly what I proposed as well. Except for the Taxonomies option. That would work as well of course.

What I don't see is possible is adding content fields on a per content item basis, hence my starting with "I don't think that's possible" since that's what the original question was about. That's just not possible, or is it?