6

I haven't used Views much before but it feels like I should be so I'm getting stuck in...

I think I'm missing something obvious here but how would I go about creating a view that 'mixes' several different entity types?

I have a custom field type attached to nodes, users, and also to user profiles provided by the Profile2 module. The field contains lat/long data (I know OpenLayers etc. provide this functionality, the field type was built as an exercise).

How can I create a view that contains all of the different entities that have this lat/long field associated with them? I'm basically after a simple table with 'Entity Title', 'Lat' and 'Long' as columns.

All of the different entity types are separated when I create a view (Content, Users & Profile) and I can't find a way to group them together so to speak.

Is this possible with Views or is not quite there yet with regard to entities?

6

Views uses a term it calls base table translated into SQL it is the table used for the initial query

SELECT something FROM {base_table};

The thing is that what you want to do is a bit atypical, instead of doing

SELECT something, field_item FROM {entity} LEFT JOIN {field};

You want to do

SELECT something, field_item FROM {field} LEFT JOIN {entity};

In order to do this you need to use the field you are after as the base table. By default this is not possible, but it's not much work required in order to do it. What you need to do, is to use hook_views_data or hook_views_data_alter and add the data for the field table and make it selectable as base table displayed when you create a view.

There's a lot of doc on how to do this (the Views doc), and I have written this in one or more answers here. So I won't bother explaining how to do this.

  • 2
    Thanks - nice answer. Would love to see links to the other places you've addressed how to do this. – squarecandy Jun 9 '13 at 3:04
  • can anybody explain plz how to do this? – Umair Sep 30 '16 at 16:38

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.