filtering a Drupal View with ORed criteria - drupal

I'm attempting to present a Drupal View that shows nodes in which the user's e-mail address shows up in one of two CCK text fields. Unfortunately, this doesn't seem to be possible using the stock version of Drupal's Views module - there doesn't appear to be a way to combine filtering criteria (except ANDing them), nor does their appear to be a way to do the custom logic for the filter's setting...
Is there a simple way of directly injecting additional information into a specific View's WHERE clause? If not, can it be done in another way?

You can use the views_or module. It's still in dev but looks promising.
The other option is using hook_views_query_alter with $query->add_where() you should be able to add an or clause. You can also use it to add your aditional WHERE clause that you asked for.

Related

Drupal 7: make values of a field dependant on other field value

I created a content type with different kinds of fields (text, dates, entity relation...).
I have 2 dropdown fields (related to 2 taxonomies). I would like that the second dropdown values change based on the value of the first dropdown.
I found the module Dynamic dependent fields (https://www.drupal.org/project/ddf) but after installing (and enabling) it I cannot find any configuration about it.
Could you help me?
Thanks
Update: I found the Reference field option limit module (https://www.drupal.org/project/reference_option_limit) but after enabling it I don't know where to set what I need.
Having a look at the source of the module, it looks like there should be a setting when editing a select field.
You may want to consider a different module though, such as:
Conditional fields or
Field conditional states
This is assuming that the dropdowns are not just different levels of a single taxonomy, which the other answer about hierarchy select would be a better option.
EDIT, reading your question again I see it is 2 different taxonomies so Hierarchy select probably wont work for you.
It is possible and easy to achieve that with this module: https://www.drupal.org/project/hierarchical_select. It is the most popular I think. Maybe you could have a look at it.
I personaly don't know the module you've installed.
This module defines the "hierarchical_select" form element, which is
a greatly enhanced way for letting the user select items in a
hierarchy.

Drupal 7 - Administration - Find node by it's field value

I'm looking for the way for the site's administrator / moderator to find / filter the list of nodes by some field custom value. Field value could be defined by radio / text / checkbox etc.
Default content listing proposes only few filters, it's not enough for sites with huge amount of custom nodes.
Use an EntityFieldQuery object, documented here:
http://api.drupal.org/api/drupal/includes--entity.inc/class/EntityFieldQuery/7
The documentation has no examples (ugh), but there's a thread here with some:
http://drupal.org/node/916776
EDIT: Ah, you're talking about administration and not actually writing a module to do it. If that's the case, use a view with exposed filters, like the other guy said. :)
Maybe it would help to use a view for it, where you set filters, so that you get the desired listing.
I had to test this, but I've just confirmed. Views in Drupal 7 can indeed filter across multiple content types w/ custom fields, and still have filters apply to those custom fields. They seem to treat the nodes w/o those custom fields as empty or null values.
So for instance, I have article and blog content types. Blog has images, article does not. I can sort or filter on the image field, even though article doesn't have it. It simply assumes the field is null or empty.
This however, may not solve your problem of having a large number of custom fields. If these are dynamic (i.e. they grow over time) you might be in trouble. If, however, they are set, and just a very large number, you could manage this.
So while there is no automatic add all fields, which I believe you mentioned in a previous post, you could feasibly search on a large variety of the fields. Even exposing fields that you don't necessarily display in the table, but can then search on. Or changing the fields you expose or display on a per page basis in the view. All from one view. And then you could export the view to bring it over to the other sites.
I was going to try and attach the exported view, but the export is rather large for inclusion in an answer, I think. Please let me know if you think I should still include it, or if you'd rather I can simply send it to you through a PM. Let me know!
EDIT: I decided to include a link to an export of the view. http://greggalante.com/sites/greggalante.com/files/cross_type_view.txt
http://drupal.org/project/search_api

Custom search form in Drupal 6: Views/Panels or custom sql?

I use CCK in Drupal 6 and I need to build a search form in Drupal with 8-10 fields used as a filter. When the user submits the form I need to make a query on the DB applying filters and presenting the result on a table.
I know how to do this programmatically by building dynamically the SQL-where condition (joining node and content_type_xyz tables) but I would be interested in learning how to do it in the "Drupal way". I think I would have to use Views and Panels but I don't know if they can be easily implemented in situations like this. I've tried to build some sample views but I think to be faster in creating code by hand.
If you want custom searches you need IMO to do 2 things:
Hook yourself into _search so you can use Drupal's display for the results. Inside this form, you can create your queries for the database or load other content as you wish, just be sure to use pager_query.
Extend the search form that already exists or built your own. I suggest buliding your own. use what is already existing from Drupals search form. This way, you have a clean way of how to do this.
There is actually no need to use any fancy modules (that doesn't mean you should rule them out, but a search is something so esential that it is quite well handled with the basics).
Using the above, you'll get a native search form with all it's power and can make use of global paging options.
If you do it using views you will only be limited to the filtering you can do using SQL. Views is an SQL builder, and does not contain any 'proper' search functions. That said, it sounds like Views will do what you want; if you create filters under views and then click 'Expose this filter', you will suddenly see fields that allow the user to enter something to filter by appear.

Filter a view by user-created tags in Drupal?

I'd like to add a block to the user profile that shows them content listings in their groups based on tags that they have in their profile.
(ie: someone puts a bike up for sale, the user has listed "bike" on their wishlist, it should show up to get their attention)
Since these tags vary user-to-user, I'm not sure exactly how to set up the filter.
Going a little farther, can I sort them by the number of matching tags?
I've found that taxonomy terms and views can be very tricky to get right. The main problems is that taxonomy terms has a one to many relationship with nodes, and views is built to be generic.
It might be quicker to create such a block in a custom module instead, because you may very well get stuck in views before getting what you want. Also you most likely have to create your own sort plugin for views, to get the sorting you want. I haven't seen any module creating something like that, and I don't think it's possible with views core. Creating plugin for views can be very harry, the first time you do it, so unless you know your way around views, I think you will have more luck just creating a block yourself. It's much simpler, than having to extend the views functionality.
Have you looked into Views? You can set up a block with views that retrieves (almost) ANY information from the database.
In your case, you can filter the information that you need and that belongs to the current user, also, sorting is doable via the Views administration.

Drupal views: Allowing users to choose sort criteria on node display

I have some nodes I am displaying in a view. They are displayed as nodes, unformatted. I would like the user to be able to choose from some predefined sort criteria ( via drop down list or similar).
So they could pick recently active, most commented, newest, etc., and re-query for new results.
Its easy with tables because you can make the labels clickable, but I do not know how to have similar functionality with a raw node preview display.
Just a thought, from me to me, and for anyone else who may be trying to do this.
An easy, sleezy option would be to just add another page view for each of the required sorts, and provide a link to these other views in the header of each of the pages.
This could also allow for (easier) linking to the individual sorts, so say if you have a sidebar block displaying recently commented nodes, you could adjust the .tpl.php of the block to have the title link to the view displaying the full set of recently commented nodes.
also im pretty sure there should be a way to do this with arguments, but i dont know how
Views 3 supports exposing sort order (just like you can expose filters)
Select the sort order (e.g. add sort by node creation date, then click on the settings for that), you should be able to expose the sort order to the end user. This is just like clicking on the settings for a filter and then choosing to expose it.
Standard views isn't going to support this, so IMO you're best off implementing a custom solution using just a plain old view and this jQuery plugin. You can either do this at the theme layer (the same way as any other JS in a theme) or a custom module (via drupal_add_js() to add the plugin and your bit of custom code). Either way will work, although the custom module has the obvious benefit of being theme independent (and thus more portable).
If you go the custom module route, please consider releasing it as a contrib module on http://drupal.org.

Resources