display other fields of a entity reference field - drupal-7

Let's say I have a content type of "person", which contains details about that person. I have another content type of type "house", and I want to use an entity reference field to select different people, but when the content type is displayed I want not just the person's name (the title of the referenced node) but all the other details. I have tried selecting the View mode "Rendered entity", with view mode "full content", which I would expect to display all the fields - but I can't get it to work - it just displays the title.

Have you set up the full content display to display all fields?
Go into your person content type - go to custom display down in options.
Then up in the top right corner you should have default, teaser, and full content links.
Go into full content and make sure all fields are being displayed.

Related

Same View, different displays, One page, same exposed filters. Possible?

I want to list my content categorically within view. The problem is that I want all of it to be filtered through exposed filters.
Here is what Content Type looks like:-
Content Type (MyContent)
Title
Body
Category (it has three categories in it "Category1, Category2 and Category 3". User has to selects one when entering the content)
Now I created a view which lists all of the content linearly (like a normal list) and I have exposed filters on top, which filter the content, but now I am not sure how to proceed when I have to show the content as:-
Any Idea what I should do to achieve this? What should I do in this scenario?
I'll be grateful to you valuable assistance.
Best.
You can group your results together. Under the Format option in views next to your format type (unformatted list, etc...) click on Settings.
In this menu you'll see "Grouping field" this will allow you to specify on which fields your results should be grouped. The field needs to already be included in your display.
Once you enable this you'll probably notice that that field is now displayed twice. You can just go into that field and check "Exclude from Display"

Drupal 7 - Entity Reference - Display only items related to node that is related to another node

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.
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.

contextual filter views in drupal 7

I have a content type which has a Entity Reference field (field_industry). I am trying to create a menu on a page containing all the nodes which have an enity reference which is the same as the title or URL of the page the view will be displayed in.
EG
I have a page called glass, and 2 pages below which have the Entity reference of "Glass". I have created a view, which shows the title field. If i add a field to the view (field_industry) and set it to =glass. But it needs to be dynamic. How would i do this with "contextual filters"?
The entity reference field stores a reference to the actual node so you do not filter on the string glass you filter on the node id.
If my understanding is correct when you view the glass node you want to show a list of all nodes that reference the glass node.
Create a view showing content of the type you want to display, also create a block with that view.
Add a contextual filter on the field that is used to reference the material.
For "When the filter value is not available" check "provide default value" and then "type" should be "Content ID from URL"
Go to admin/structure/blocks and place the block where ever you need to display it.

Drupal 7 Entity Reference and content type field display

I have successfully created an Entity Reference as one of my content type fields. I am using the Select List as my widget type. The content of the Select List defaults to the node title. This is problematic in my case and I would like to display different field content of that node. Anyone know how to do this?
When you create an entity reference field in the field settings you can specify that it uses an "entity reference view" to create the list of options.
So in Views, create a new view that outputs the field you want for the Entity type you want. Set the display type to be "Entity reference" (you may need to install the Entity Reference view Widget module)
then in the the field settings for your field set it to use that view.

Styling views in Drupal 7

I developed a content type of "sale car". Now I'm developing its view to display a brief list of Car Ads with some basic fields (car, model, color, price, link to full ad) inline of each other like this:
BMW, 120 d $X,xxx,xxx.xx
Royal Blue, Automatic, View Ad
I'm wondering how can I achieve this style? What style format I should use: Table, Grid or something else? Or do I need to get it done through coding?
You want to create a view that is a list of fields.
Once you've got this, add the relevant fields into the view and you should be done.
Choose the relevant format from the format link, check the preview and you should have your view.
To create the view structure:
Node 1 Node 2
Field 1 Field 2 Field 1 Field 2
Field 3 Field 4 Field 3 Field 4
Add all four fields to the view. On each one select "exclude from view". At the bottom of the field list, add a new "custom text" field.
Do exclude this one from the view though, that's important.
Go into the custom field and in the textarea you can enter HTML code and use the replacement patterns to output the field.
For example:
<h2>[title]</h2>
<ul>
<li>[field_one_name]</li>
<li>[field_two_name]</li>
</ul>
<ul>
<li>[field_three_name]</li>
<li>[field_four_name]</li>
</ul>
Get the name's from the Replacement Patterns box under the textarea.
Then select whatever format you think is right. I think you're after a grid.
Drupal provides a way to style the view.
Go to your view.
Click on 'Advanced' link at right side.
Click on link after the label 'Theme'.
You will get the list of templates used to style the view.
Create your own template with one of the given name in the list for
specific fields. e.g. views-view--VIEWNAME.tpl.php
You will get the view of your own style.
This is how the Drupal views styling works. :)
Styling views in Drupal 7:
Add field(which to display) and check the option "Exclude from display".
Now go to "Rewrite Results" and check the option "Rewrite the output of this field"
and below there is a section called "Replacement patterns" where all the added
fields appear as a variable(saying variable just for easy understanding)
Like :
[title] == Content:
Title[field_event_date] == Content:
Event Date[body] == Content:
Body[body-value] == Raw value
Above there is a text ares called "Text" where you can customise your style
for this field(Not good practice follow step 4 for better)and clicl "Apply All".
Now add one more field(this is an extra field) called "Global: Custom text"
DO NOT check "Exclude from display" and below text area called "TEXT"is
the area where we will be writing our HTML codes for styling the views
using all the fields which are avalable as token here under the option
"Replacement patterns".
Click on the "Apply All", And YES its done.So simple and cool na??

Resources