3

I'm building a site with a "function" content type, to manage a list of functions and their arguments. Because arguments can be zero or more, and have multiple properties (name, required, usage notes) it seems best to handle them as a field collection, using field collection table as the input widget. Therefore, on the node edit form for the "function" content type, the input widget would look something like this:

field collection table input widget

On the display side, I need to display the argument data in at least two ways: (1) in a table formatter provided by field collection table and (2) in an arbitrary "syntax" format, where only the arguments are output, but with some kind of visual indication of which arguments are required. So, something like this:

field collection display

My questions:

  1. What's the best way to add a custom formatter for the field collection (i.e. in code, in a field template of some kind, using the custom formatters module, etc.)?

  2. What's the best way to output two instances of the field collection field, each in a different format?

I do have Display Suite installed on this site, if that helps. Also interested in any general advice if there's a better way to handle this use case.

1

This sounds like it would be best output as two separate views. The first view would be set in your first format and the second in the other format. Probably using a view template of some sort. The issue is that the field collections attached to the node are actually referenced separately and you only know they belong to the same node because the field collection entity has a reference to the NID.

The view would reference by nid in the contextual filters.

The other option is to programmatically load the fields via the node.tpl.php file (assuming you are loading them on the node page). in which you simply gather the data via the $node object and display it as you need.

https://drupal.org/project/field_collection_views

https://api.drupal.org/api/drupal/modules%21node%21node.tpl.php/7

http://www.youtube.com/watch?v=_GlfYhsk3X0

  • Thanks, Chad. I had looked at field collection views earlier as well, and I need to try it out to see what it's like in production. And working node.tpl.php is for sure a good option but with display suite – Dave Bruns Nov 22 '13 at 19:48
  • [continued]... installed, there I feel the urge to keep the Manage Field display synced what's actually being displayed. It's silly, but but I still hesitate to put solution in a template. – Dave Bruns Nov 22 '13 at 19:55
  • If you do have display suite another options is to create two different view modes. Then look into creating a view for those view modes. Then after that create a dynamic view which you could pull into your full content or defautl view mode, which will pull in those views into the view mode. Let me know if that makes any sense – chadpeppers Nov 23 '13 at 21:55

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.