3

How do you create a taxonomy listing when the field is being used in a field_collection field type?

I'm working on modifying the Article content type for a newspaper website; specifically, I've added two field collections: one is a byline, with two fields ("author" [taxonomy] and "position" [text]; e.g. "Ændrew Rininsland, Production Editor") and another is an image, with three fields plus the image ("caption" [text], "author" [taxonomy], "organization" [text]).
Both of these are set to have unlimited values, such that each story can have multiple bylines and multiple photos, each with its own caption and photo credit.

What I'm wanting to do now is use the "author" taxonomy term to create a listing of each story each author/photographer has contributed to. Simply going to the term's taxonomy page doesn't work; that only lists nodes with attached taxonomy terms, not fields (such as a field_collection). See this issue.

  • Is using views out of the question? The stock "taxonomy" pages are not very useful. – Jonathan Rowny Jan 5 '12 at 19:09
  • Nope! You can definitely use Views -- I have no idea how one would refer to the parent node a referenced field_collection field is inside of. – aendrew Jan 6 '12 at 12:40
  • Two days left on the bounty...! Anybody?! – aendrew Jan 10 '12 at 12:02
1
+50

Ultimately, I'd build a view that looks at the taxonomy term and then uses a node reference for other information supplied. The Second post in your issue points to another issue that contains a lot info about views integration and node references. If you can't find a solution there, I'd add your needs into the mix and follow that discussion.

  • Mind supplying a bit more detail? – aendrew Jan 6 '12 at 12:53
  • ........Please? – aendrew Jan 12 '12 at 14:29
  • @aendrew, sorry, I did some research but that was the best I could track down. I'm not familiar with how field collections work. Good luck. – mtro Jan 12 '12 at 14:31
  • Well, thanks anyway. Awarded bounty because it's set to expire. Leaving question open if anyone has a better idea. – aendrew Jan 13 '12 at 18:30
1

I finally got around to solving this issue, and managed not one but TWO different ways of solving it.

The hard way (writing a module): http://drupal.org/node/1291246#comment-5811912

The easy way (creating a view): http://drupal.org/node/1291246#comment-5812572

Quoting the latter:

Using the example above (unlimited value field collection named "field_bylines" containing a taxonomy field "field_author" and text field "field_position"), you can accomplish pretty much the exact same thing by creating the following view:

  1. Create a view, call it whatever you want. Make path something like "author/%"
  2. Click Advanced, Add a Relationship. Choose your field collection; in this case, "Content: Bylines"
  3. Add a Contextual Filter. This will be the taxonomy field (I.e., "field_author"), should appear named something like: "(field collection item from field_bylines) Field collection item: Author". Tell it not to display anything when filter value is not in the URL.

Tah-dah. Should work. If you want your field collection listed in the results instead of the default user creating the content:

  1. Under Format, click "Content". Change to "Fields".
  2. Under Fields, Click Add and select "Content: Bylines". Change formatter to "Fields Only" and uncheck "Create a label". (Last two are my preference to tidy UI up)

Note that you'll have to supply the author's term id to the view instead of the term name (I've never figured how to supply a term name as an argument as opposed to a tid...).

Hope this saves somebody the frustration it caused me. Field Collections really need better docs...

0

Below are the steps to use your field collection taxonomy field into exposed filter.

step1 - create a content view.
step2 - add your field collection taxonomy field into relation.
step3 - also add same field into filter criteria and set it as exposed filter.

now your taxonomy dropdown should be appear with working condition.

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.