1

Let's say I have a general content type called "Zoo". A Zoo may have several animals (animals will have a title, image, and description). Now at first, it may seem like I should just have an "Animal" content type and then somehow relate them, but all animals are unique to the zoo. (If two zoos contain a tiger, they will be completely distinct tigers, with their own images/titles/descriptions).

I have a view (already working), that lists the animals. I'd like for the animal titles to link to a page where the animal information (image/title/description) is available.

Because each image (animal) needs it's own respective title and description, and a Zoo may have several images (animals), I've tried to find a way to relate the information, since simply adding fields to the Zoo content type is fruitless.

The closest module I've found is Field Collections, and I'm technically able to reference the information correctly. The problem I'm having with it is, in the view list, I can't figure out how to show the titles of the animals and have them link to somewhere useful.

This "useful" place they link to is what I referred to previously, somewhere with the animal's information (image/title/description).

I know this example seems a little convoluted, and almost like I should use the node reference module. But the real use case requires not having to make separate nodes in separate areas and relating them, but rather making all of them at one time.

  • Do I get you right, that the main chalenge is to give the user a chance to create a zoo and all animals on a single page? – BetaRide Jul 2 '12 at 14:52
  • @BetaRide Yes, not only for user experience reasons, but because each of the animals would be part of one zoo, and I think it makes the most sense semantically. – Matthew Jul 2 '12 at 15:37
2
+25

I would advise node References and Entity Views Attachment

  1. Create 2 content types: 1) Zoo - 2) Animals
  2. Animals has a "Node reference" to a Zoo
  3. Create 2 views: 1) Zoo - 2) Animals - Attach entity contents by relating them and contextual filters on nid

This way you can create Zoo pages [node] with all the animals in the zoo On the animal pages [node], you can show which zoo(s) the animal belongs

You can also create pretty overview [views] pages

0

If I get you right, you don't need any properties for the zoo. If this is true you could handle the zoos just as a vocabulary with a term for every zoo. Or to get even a simpler structure just create a text field with a list of zoos to choose from.

But to be honest I think that it would give you a much bether data structure to create a content type for zoos and a content type for animals and relate them using node reference. Maybe you could tell us more why you don't want to do this.

  • While the data structure makes the most sense to have theme separate, in this use case, I don't want the user to have to create them separately and relate them when the animals will never be many to many and always make sense to be part of the zoo as far as creation goes. – Matthew Jul 2 '12 at 12:22
0

If you want to be using Field collections, then I think it will be difficult to display each animal on a separate page (That could be possible if somehow you can configure the "Multiple Fields Setting" of Views dynamically). However, if you want to display only the titles of the "animals" in the "zoo" node and then link the titles to a page that displays all information about all the animals in the zoo, then that is possible.

  1. Install the "Entity view modes" module (http://drupal.org/project/entity_view_mode). This will allow you to add more view modes to your Field Collection. Add a custom view mode e.g. "Title only". Now in the display settings of your Field Collection, enable custom displays for the "Full content" and "Title only". "Full content" will have all the fields, "Title only" will have just the "Title" field.
  2. Your main view that displays the title of the animals should be already having a Contextual Filter to the Content Id (Nid). In your main view, select the Field Collection field and select the Formatter as "Fields only" and the View mode as "Title only". Then under the "Rewrite results", check "Output as link" and put the path as "zoo-animals/!1". The path "zoo-animals" is described below.

  3. Create another page view and put the path as "zoo-animals/%". Add a Contextual Filter to the Content Id. Select to display Fields and then add the Field Collection field, this time selecting the "Full content" view mode.

This way, you have one view, with the zoo content that lists the animal titles which are linked to the 2nd view that displays the full details of the animals.

0

A solution I used recently was references + nodereference_url, you may set it up something like the following:

  1. The INDIVIDUAL ANIMAL node type has a field ZOO which is a node reference to a specific zoo
  2. The INDIVIDUAL ANIMAL type also has a field ANIMAL SPECIES which refers to a taxonomy term
  3. When visiting the ZOO page as a content administrator you could click "ADD INDIVIDUAL ANIMAL" and you would need to select the species

This way you get to define generic properties and fields of an ANIMAL SPECIES while allowing you to define custom fields for a specific animal. The downfall of field collections module is that it does not give you fully fledged nodes to manipulate.

0

I recommend that you stick to the field collections approach and either:

  1. Display each animal's collection in its entirety on the Zoo page and use JS to hide appropriate fields and display them upon click perhaps in a lightbox.
  2. Write some code that mimics the node display to display specific field collections based on their own custom URL. I don't believe that this should be too difficult to write as there should be some simple API calls that you can leverage.

Good luck!

0

On a recent project I did exactly what cateye describes (node reference + entity views attach) but add in nodereference_url like Duncanmoo mentions. It displays an "Add Animal" button on the Zoo page and automatically fills in the node reference to the parent Zoo on the Animal page. I think it's far easier than using Fields Collection. Animals really are a content type and not extra fields in a Zoo.

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.