Query Filtering by ListBox Values

Topics: General
Editor
May 23, 2012 at 4:58 PM

I have an Enumeration field attached to a custom content type of "Client". This enumeration is of type ListBox and I put in a bunch of string values that correspond to the product names (Title part) of the content types I want to map them to.

I placed a projection widget on these product pages with a query to retrieve clients associated with this content. My filter in the query is:

Content Type is "Client"

And

Client.Associated Products contains '{Content.DisplayText}'

For some reason this is not returning the clients that I map in the listbox for each product. Any thoughts on this? Does the contains work with ListBox? Any easier methods to achieve such a mapping?

Editor
May 23, 2012 at 5:48 PM
Edited May 23, 2012 at 6:09 PM

Based on some preliminary test, it looks like it is filtering on all the values in the enumeration list box and not the "selected" values as it indicates. I will investigate further.

I tried swapping out the different enumerations and it looks like they are not checking the selected values, but just the containing value. I changed the filter to "equals" instead of "contains" and that did not change it either.

Coordinator
May 23, 2012 at 6:16 PM

The issue as I understand your scenario is that {Content.DisplayText} might be empty. I am assuming you expect {Content} to be the currently displayed content item ? If yes then it's a bad assumption, because a page can display multiple content items.

One solution could be to provide a token in the alias module which would return the content item associated with the current url. This would make more sense, and work in your case. Something like {Aliased.DisplayText}.

You want to file a bug (aka feature request) for this one ?

Coordinator
May 23, 2012 at 6:18 PM

A solution in the meantime would be to change the template of Client and insert the values from the list.
Another technical solution would be to create a "Related Content" part, like David Hayden has done recently: http://www.davidhayden.me/blog/orchard-cms-related-blog-posts-custom-module

Editor
May 23, 2012 at 6:37 PM

I agree with you saying the DisplayText may be null, but I also hardcoded the value into the filter string box and it still evaluated to true. To me it seems like the piece of functionality that is broken is the comparing of the selected list item values to the string in the filter box or the token.

I can file a bug for this, but could you point me to maybe where this is located so I can fix it and then submit the patch as well?

 

I will also look at David Hayden's related content part as well. This may be what I need.

 

Thanks!

Coordinator
May 23, 2012 at 6:54 PM

If you can't filter on a hard coded text, yes, file a bug

Editor
May 24, 2012 at 11:41 AM

I have submitted it as issue 18706. I think it resides in Orchard.Projections/Providers/ContentFieldsFilter.cs. I am just unfamiliar with how this works to filter here. It looks like it is passing the "Value" property on the field to filter on. If that helps :)