Allow user to choose from his own referenced nodes - drupal-7

I have two content types:
Business listing
Product listing.
"Product listing" has an Entity Reference field. This field points to the nodes of "business listing". I want to allow user to choose from his own "business listing" nodes (during adding a "product listing" node). I have created a view to list the nodes of "business listing" type and have added an Entity Reference display to the view. Then I selected the view Under "Entity selection". Now, I have a problem in adding proper contextual filter. I have added a contextual filter of "Content: Author Uid" and selected "provide default value".
a) if I select "USER ID from logged in user" as default value:
This solution will break if an admin is editing the node. The field will then show only nodes the current user (admin) has created.
b) if I select {"User ID from URL" and "Also look for a node and use the node author"}: This solution will break if an user is adding a new node. The field will not show any nodes! http://example.com/node/add
please guide me

Related

How use one field of a form to populate other fields in Bonita?

I have a form variable of type external API called customersList. It is a list of customer objects. In my form, I have a Customer Name and Customer Id. For the Customer Name, I use an auto-complete widget. So, when I type something in the Customer Name field, it will give me a list of suggestions. When I click on one of the suggestion, I want the Customer Id field automatically populated with the information corresponding to the name I choose.
For example, the first object of a customersList variable which is:
customersList[0] = { "customerName" = "One Time Customer", "customerNumber" = "0000" }
Thus, when I choose Customer Name field to be One Time Customer, I want the Customer Id to be set to 0000 automatically.
I set the value of the Customer Id field to be customersList[0].customerNumber. But, it is static.
(please note: customerNumber represents Customer Id)
Any tips on how to do it?
Sadly the default autocomplete widget won't let you achieve such use case.
In fact the default autocomplete widget can take a list of JSON object as "Available values", can use one of the attribute of those objects as the display value ("Displayed key" property) and use it for autocompletion but it will only store this value (i.e. the one being displayed).
In your use case it means that you can use your customersList for "Available values" and customerName for "Displayed key" but you will only be able to save the customerName in "Value".
The good news is that a custom widget that do just what you want is available as a community contribution. Checkout the project page to download it and then import it in your UI Designer. An example of usage of this custom widget is also available for download from the project releases.

Drupal 7: How do I use views to display information from the current node?

I have a Drupal 7 question. I would like to display certain pieces of information from my current node using a view.
I can use views to display information from other nodes easily by setting filters and other sorting features. That's no problem. However, I want to display information from the node which is currently opened. So, for example, if I'm on a page (node: 117, title: news), I can display all the images from that page, plus captions, by creating a view.
The logic, I suppose, would be to create a view with a filter (or contextual filter) stating that the node has to equal the current node, but I don't know how to do that.
Does anyone have any advice? How do I instruct a view to display information from the node which is currently open?
Thanks!
Edit the view
Add Content: Nid in contextual filter
In contextual filter options
WHEN THE FILTER VALUE IS NOT AVAILABLE
Select "Provide default value"
Type: Content ID from URL
Now the default argument will be the nid of the current node.

Drupal 7 unable to get referenced node in view

I have a node called "Student" I have another node called "Personal details".
I have made relations between them using entity reference module.
Now I am creating a view to get details of all students. I created a view of students and selected Content "Personal details" on fileds of the view. But I am only getting the id of the "Personal details".
I am struging to get the name and other fields of personal details node.
I used Relationships-> Entity Reference: Personal details and added content entityreference in fields but it is not displaying aything when i printing the view using get_view API.
Please help me on this.
I think this should work. Try to create a view for all types.
Select the fields that you want to display (the fields from students and personal info ). Chose to display both Id's from Student node and from the Personal info node, but make 1 of them invisible, to not be shown. ( you will understand why in step 4 ).
Add a filter, the Global: Fields comparison.
Select the two fields that have to be equal (the ID's).

Drupal 7 Views: Term filter with relationship

I have 2 content types:
One content type is named: "Offer". This content type includes a reference field to choose one hotel, form the other content type: "Hotel". The content type "Hotel" has a term reference field called "sports".
Now I want to build a view filter, which uses the content type "Offer", and uses the sport terms which i get over the hotel relationship.
I already tried to create a relationship on my own:
Reference to the hotel
Added taxonomy field sport with the relationship to the hotel, which i created before
Then i added the taxonomy field to my filter, and selected the Relationship in the drop down menu.
But this doesn't work at all.
Anyone can help me?
Regards M.
The view should initially return the hotel content type.
Add a optional relationship to the offer reference field, this will give you access to the fields in the offer content type. Once you've done that you should be able to add whatever field you want as an exposed filter.
To get the sports working you may have to add the relationship Has taxonomy term in order to get what you want and then add the term as an exposed filter.
Use the patch over at https://www.drupal.org/node/1492260 for autocomplete.
A select list should work the same way as with this patch, but it's built-in. In either case, you have to enable it by checking the checkbox in the content type field config.

Associate a Taxonomy term to user who creates it

I have field Company Name which is a term reference to a vocabulary with same name. when user types the field if name already exists, so auto complete showed that or else it will be added as taxonomy term. let us consider "BBB" is the company name he entered.
On next scenario when another user keying in this company name as "BBB" so its already their in the taxonomy so i have to send a mail to the user who created added the term "BBB" first.
I tried using rules module but i couldn't find way to get the user who created the term.Meanwhile i use Profile2 module so writing submit handler is best?
You can add a user reference field to the taxonomy entity so it will have a Name, Description and that User reference field.
Then you have to run a Rule on events "taxonomy_term_update" and "taxonomy_term_insert" that will save the user id on that field. See the rules code example on a Drupal.org related issue.

Resources