5

I have a content type (content type X) containing a Field Collection field. This Field Collection field consists of a Node Reference (content type Y) field and a text field.

I would like to create a view where I group items based on the nodes selected in the field collection field.

An example:

Node 1:

Field collection:

  • Node ABC : text here
  • Node BCA : text here

Node 2:

Field collection:

  • Node BCA : text here
  • Node CDE : text here

The view showing these items would look like the following:

ABC

  • Node 1

BCA

  • Node 1
  • Node 2

CDE

  • Node 2

How would I be able to create a view like this? I'm sure I need to use relations, but honestly I have no idea where to start.

Thanks for any help in advance!

  • Have you try the "Grouping field Nr.1" in "Format" Settings? – CocoSkin Jul 20 '15 at 16:34
2

Very nice question!

I give you every detail step by step, including the structure of content types.

First install Field Collection Views module. This will add a default View in Views menu. Its name is field_collection_view. Clone this view (recommended) or edit the existing one.

Content Type X

This is the Manage Fields of this content type

enter image description here

It contains a Title and a Field Collection field that I called xxx. This is the xxx

enter image description here

It only contains an Entity reference to y, I called it field_reference_xxx (you can also include other fields, for our purpose it is unnecessary).

Content Type y

It only has Title field and nothing else.

I inserted the exact content you included in the question.

Node1 (x) to abd and bca

Node2 (x) to bca and cde

field_collection_view View

This is the main work to do. The default View of field collection is in /admin/structure/views/view/field_collection_view path. Open it.

First you need to add two Relationships :

Entity Reference: Referenced Entity

A bridge to the Content entity that is referenced via field_reference_xxx

Make sure to select referenced not referencing

and the second one:

Field collection item: Entity with the xxx (field_field_collection)

Relate each Content using xxx.

I supposed the Contextual Filter for selecting is Title of content type y, right? so let's do it. add Title as contextual filter and make it to use (Content entity referenced from field_reference_xxx) Content: Title relationships.

So far so good. Now go to Fields section. select Title as a field and make it to use (field_field_collection) relationships. I mean this

enter image description here

AND NOW OUR WORK IS DONE!

In the aggregate This should be your configuration

enter image description here

For testing I give you the following screenshots to make sure it works

Without any value

enter image description here

With bca

enter image description here

With abc

enter image description here

and cde

enter image description here

Good Luck!

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.