0

I have 3 Content Types: Restaurant, Menu, and Menu Item.

I've set up my Restaurant content type so that when a 'Restaurant' is created I have the ability to create a Menu with Menu Items, using the Entity Reference and Inline Entity Form modules. This is all working well.

The part I can't get to work is to display the Menu items correctly in the 'Restaurant' page. I created a Menu View block, where I added Menu Item fields, and filter it by Content Type 'Menu Items'.

When I place this block in my restaurant page, I see all menu items being displayed...

How can I display only the Menu Items that are related to the Menu content type that related to the Restaurant being viewed?

Edit: In my 'Restaurant' content type I created a field_menu which is an Entity Reference to the Menu content type, and I use the Inline Entity Form module to allow the creation of 'Menu' entities within the 'Restaurant' creation page.

Similarly, in my 'Menu' content type I have a field_menu_item which is and Entity Reference to the Menu Item content type.

barrakuda
  • 11
  • 3
  • How did you setup the entities? You have a field Menu in restaurant content type that is an entity reference to menu content type and a field menu item in menu content type that is an entity reference to menu item content type? – geoandri Oct 20 '14 at 19:22
  • I edited my question and added more details. Thanks! – barrakuda Oct 20 '14 at 19:37
  • it 's quite complicated due to entity reference through entity reference. I made an attempt but didn't work out. I ll try again and get back I hope. – geoandri Oct 20 '14 at 19:58

1 Answers1

0

In that case you should add the relationship between menu items and restaurants in order to access the field menu in the menu items view. You can do this in the Advanced area relationships and add the entity references that you need. In your case you should add the menu referencing field and the restaurant referencing field. They should appear similar to

  Entity Reference: Referencing entity 
 A bridge to the Content entity that is referencing Content via menu_item_field

All the above should result in the appearance of the menu field in the filters of the view. When the menu field will be accessible in the filter of the block view you should add a contextual filter for that field.

Then in your contextual filter in the "When the filter value is NOT in the URL" area select "Provide default value" and Type "PHP code" (You should have enable php filter for this). In your php code area you should have the following code

$node=menu_get_object();
return $node->field_your_machine_field_name['und'][0]['target_id']; // this is the field you will use for filttering.It should be the menu field in the restaurant content type 

Hope i didn't confuse you. It's not a simple task though.

geoandri
  • 2,360
  • 2
  • 15
  • 28
  • I don't see an option for restaurant_field in the add relationships popup. I only see options for field_menu and field_menu_item. – barrakuda Oct 20 '14 at 20:00
  • after you add the first relationship , the second one should be available – geoandri Oct 20 '14 at 20:01
  • I don't have a restaurant_field in my Menu content type, so when creating the view I'm not seeing an option to select "Entity Reference: Referenced Entity... via restaurant_field" The way I'm linking the content types together is like this: Restaurant > Menu > Menu Item. So in the Restaurant content type I reference the Menu, and in the Menu I reference the Menu Items. This is how it seems it should be set up but I'm not sure if I should be doing something else. – barrakuda Oct 21 '14 at 14:33
  • Also, the view is being filtered by Menu Item content type because I'm using filters to filter Menu Items by food type. – barrakuda Oct 21 '14 at 14:37
  • Thanks for your help in advance, I'm going crazy over this... I've been trying to find a solution for many many hours now.. :( – barrakuda Oct 21 '14 at 14:38
  • Be careful on the minor difference between Referencing entity and Referenced Entity on the relationships. – geoandri Oct 21 '14 at 14:50