Drupal 7 Views: Term filter with relationship - drupal-7

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.

Related

Drupal 7 - assign several products (items) under each category

In D7, I have created a taxonomy (say categories) and set some terms (say category 1, category 2 etc) within it. I have also created a 'View' based on the 'categories' taxonomy and show the categories (category 1, category 2 etc) within the sidebar (block) of the website. Just let me know how can I assign several products (items) under each category so that site visitors can see the product lists on clicking a category from the sidebar. Basically I want to develop a catalogue based website to show products/items under each category.
Kindly help me in this regard.
Good morning,
If you have not done yet, you have to create a custom content type (Structure > Content Types > Add content type) and add as many fields as you need. When you are done, you have to add an extra field named Category, of type "Taxonomy Term Reference" (or something similar, I don't know exactly). You can configure this field so that you can assign several categories to a single product.
Once your contents are created, if you access the taxonomy term's URL, all contents assigned to that category should be displayed. However, you could also define a custom view that receives the name of the category as a parameter in the URL, and displays all contents in this category in a grid, table, list, ... whatever.
Hope it helps.

How do I get the SalesForce record id in a custom field

I wanted to add a simple read-only URL-field to 'opportunities' in SalesForce that contains a link to an external webpage with the 15-char record id (used in the salesforce urls) attached to it . To do this I wen to /ui/setup/Setup?setupid=Opportunity --> fields and created a new field under 'Opportunity Custom Fields & Relationships'.
I chose a field with data type 'URL' and added a default value. I thought
"http://example.com/?sfid="&id would do the trick, but this returns
Error: Field id may not be used in this type of formula
This is a vague error. Is my syntax of a default value wrong, or am i using the 'id' parameter in a wrong way? And what is the right way to do this?
I'm new to SalesForce, as you probably already have guessed.
As the other answer stated - Id will be known only after insert meaning the "default value" trick won't work for you.
You have some other options though:
Workflow rule that would be populating the URL field after save.
Formula field of type text that uses HYPERLINK function
HYPERLINK("http://example.com/?sfid=" & Id , "See " & Name & " in ext. system")
Custom link (similar to custom buttons, they appear on the bottom of the page layout. Search them in online help)
The difference between 2 and 3 is quite minor. Custom links can appear only on the record's detail view while formula fields & other urls are well... fields - so they can be used in reports, listviews etc.
You'd have to decide which version suits you best.
This is a great question. You're right, the error is very vague.
To begin with, read some of the documentation on default fields. Pay particular attention to the order of operations:
The user chooses to create a new record.
Default field value is executed.
Salesforce displays the edit page with the default field value pre-populated.
The user enters the fields for the new record.
The user saves the new record.
Default field values are calculated before any other record data including the id are available. For this reason, they cannot be calculated based on other record fields. Especially the record id, which has not yet been assigned.
To get this functionality, you will need to create a workflow rule that fires on record creation and inserts the proper value into your field.
It would be nice if we could have formula URL fields, but we don't. EDIT: I am dumb and forgot about using HYPERLINK in text formula fields, as eyescream correctly points out.

Drupal7 - Filter view based on current user's roles?

Using Drupal7, Views3 and the Node Reference module, I'm using a view to populate a node reference field on a custom content type. (So it's a view of "Reference" display type.)
I want to filter this view to show (and allow users to select) only:
published content (OK)
content of a certain type (OK)
only nodes created by the current user (OK)
OR if the current user is admin or some other role, bypass the previous filter (3) and show all nodes (but still respect filters 1 and 2) (not OK)
Filters 1 and 2 are always mandatory; then either filter 3 OR 4 must also be mandatory. I know I can rearrange filters into filter groups to make this work. The problem is that I cannot find a way to build filter 4.
For filter 3, I had to bring in a Relationship of type "Content: Author", which made a lot of new filters appear, including the "User: Current" that I used for filter 3 (node author == current user).
For filter 4, I need to filter based on the role of the current user (not author), and I cannot find how to do that.
In the filters list there's a new "User: Roles" filter available, but it only refers to the "Content: Author" relationship, so it only checks the node author's roles. That's not what I need.
I'm guessing I have to add a new Relationship to bring in the current user data (something like "User: current"), and then filter on that data, but I cannot find that in the Add Relationship screen.
Any idea how to do that?
Thanks in advance.
Update:
Note: when editing the node reference field (in my custom content type), I see there's a "views arguments" field that allows to pass arguments to the view. It's not clear whether this field accepts tokens, but if so, maybe I could use that field to pass the current user ID to the View. But then I don't know how to use that in Views...
After posting the same question on drupal.stackexchange, I was suggested a solution using some PHP code in Views (contextual filter). It's the best solution I've found yet, so unless someone can propose a better solution, I'll stick with this one.
Here is the solution:
https://drupal.stackexchange.com/questions/38205/alter-field-settings-using-hook/38922#38922
And here is the gist of it:
In the View, add a contextual filter on Author: Uid, and use the following settings:
WHEN THE FILTER VALUE IS NOT AVAILABLE:
Provide default value
Type: PHP Code
Use the following code:
global $user;
if (in_array('administrator', $user->roles))
{return -1;}
else
{return $user->uid;}
WHEN THE FILTER VALUE IS AVAILABLE OR A DEFAULT IS PROVIDED
Specify validation criteria
Validator: PHP Code
Use the following code:
if ($argument == -1)
{return FALSE;}
else
{return TRUE;}
Action to take if filter value does not validate: Display all results for the specified field (this is what will give admins access to all results)
And that's it!
Notes:
Compared to my initial settings, the relationship (Content: Author) isn't needed anymore; neither is the "Author" filter (which was brought in by the relationship anyway).
For Drupal 6, the condition in the first PHP snippet should rather be if (in_array('super user', array_values($user->roles)))
You can allow other roles as well, simply by editing the condition above. For instance:
if (
in_array('administrator', $user->roles) ||
in_array('editor', $user->roles)
)
After adding the author relationship, there should be a new filter criteria User: Roles.
Inside your views filter criteria, you will need to have 2 filter groups combined by OR; First group contain Filters 1, 2 and 3. And the other group should contain filters 1, 2 and 4.

Can't add contextual Filter (taxonomy term ID (with depth)) to a View (User)

please help me out here:
I can't find a contextual filter by taxonomy term with depth on a view of users and/or profiles. When I make a view of content it can be chosen. I'd like to provide a filter for Regions, so Filter for Europe should result in a List of Users from all over Europe and so on.
The users are associated with a taxonomy term.
Thanks for your help or any suggestions.
Christian
Unfortunately, for user object, you cannot use the filter "has taxonomy term". What you will have to do is add the term reference field that you have created to the user object as contextual filter instead.

Auto-generate title field from other columns of Drupal 7 Content Type

I'm struggling to adjust title field of my "car" content type in Drupal 7. How can I automatically generate title field text by combining for example Manufacturer, car Model, Year columns? Also if you could comment on good use of title field and tactics to avoid/remove it.
You can use the Auto Node Title module.
"auto_nodetitle" is a small and efficient module that allows hiding of
the content title field in the form. To prevent empty content title
fields one can configure it to generate the title by a given pattern.
When the token module is installed it's possible to use various node
data for the auto generated title - e.g. use the text of a CCK field
(since 5.x).
Automatic Entity Label is a generic approach. Works with any entity type. Uses Token module.
"Automatic Entity Label" is a small and efficient module that allows
hiding of entity label fields. To prevent empty labels it can be
configured to generate the label automatically by a given pattern.
This can be used on any entity type, including e.g. for node titles,
comment subjects, taxonomy term names and profile2 labels.

Resources