I need to make a content creation form that ties in the creation of two different content types.

Imagine garage and cars as an example. There is a one-to-many relationship between garage and cars, so one garage can have 0 to many cars.

I've created the content types and established the relationship between them but I need to figure out how to best support the user in creating content. I think it is important that distinction between content types is more or less transparent to the user, so he could be creating his garage at one point, then later on come back to add cars. Or he could be creating a garage and adding two cars in one go. Or he could go in and create a car without even assigning a garage.

I imagine accomplishing this by having a form for adding garages and a form for adding cars, but near the end of the 'create garage' form I have the option of either assigning an existing car I have created earlier (probably using an autocomplete textfield) or load the 'create car' form in a modal window allowing to create a new car right before submitting the garage form (the relatioship will then be established right away).

My question is how to accomplish this best from an architectural point of view.

Should I write a completely custom module and maybe place it in a block with panels or could I get by simply by creating a hook that changes the content creation forms for cars and garages? Or maybe you know about a contrib module that fixes this for me out of the box?

Furthermore, I imagine the end result being soaked in asynchronous requests, allowing the form to be validated and saved asynchronously. For an early proof-of-concept I could live with "nested save buttons", though. I will most likely be using AngularJS for some of the realtime stuff. Should I look into exposing the content types as a REST service build and the entire page in AngularJS right away? (something I am planning to do further down the line anyway, but I also need to have something up and running quickly and I imagine a rewrite for Drupal 8 in a not too far future. So I would prefer not having to learn how to build services in Drupal 7).


The Field Collection module is a quick and easy solution. It lets you nest entities within your content type as a field. So you could have a "Garage" Content Type which then has "Car" field of type (field collection) with "Number of values" set to unlimited.

At /admin/structure/field-collections you can add fields to this Car type.

On the Garage edit form you can add cars to your garage as shown below:

enter image description here

Then while viewing a Garage node, a user with sufficient permissions will see edit and add links which work just like you would expect. See below.

enter image description here

The downside with this approach is that since the Car's information is tied closely to a specific Garage, it's not easy to move a car from one garage to another or have one car in several garages, etc. Those use cases are possible, but you will have to write you own code however.

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.