Content Picker in Orchard CMS With Content Type Filtering and Search
The Orchard CMS 1.5 was recently released and it includes a very cool Content Picker that helps you build relationships between content items. I absolutely love the new Content Picker in Orchard CMS, but it really needs to have a custom setting that allows Orchard Web Developers to filter the list it displays by content type. During a relaxing Saturday morning I created a modified Content Picker complete with content type filtering and in-tab search functionality.
Content Picker in Orchard CMS
As I mentioned, Orchard CMS 1.5 introduced the Content Picker. In the example below I am adding a product to my Orchard E-Commerce Website. A product must be added to a particular category and I am using the Content Picker to select that category. In this case, I am adding a Peekaboo Kayak to the Kayaks Category.
Modified Content Picker with Content Type Filtering
Normally when you use the Content Picker to choose a content item by clicking the "Add" Button it will display all content items in your Orchard Website in a popup window ( using proper paging of course ). The current Content Picker does have the ability to filter the content items by content types in the popup window, but I would rather the list automatically filtered on display for ease of use, etc. In this case I just want to select a product category, and having to filter it manually and have other content types like Page, BlogPost, Product, etc. in the initial list causes way too much noise. What I need is the ability to specify only those content types I want to be displayed by this Content Picker. In no time at all an Orchard CMS Developer can alter the Content Picker Field Settings a bit to provide such a setting.
In this case I am asking the Content Picker to only display Category Content Types. If I wanted to display more than one content type I could separate those content types with a comma, e.g. "Category,Product."
Content Picker in Orchard CMS with Search Functionality
Given that I have turned on content type filtering in the Content Picker for only Category Content Types, when I choose the "Add" Button only a list of Category Content Items are displayed in the dialog window. How wonderful!
It still displays the Category Content Type in the dropdown list, but it is the only one in the list and therefore cannot be changed. As you can see there is also search ( Filter ) functionality. I am not using it in the example above, but obviously one could type characters in the filter and click "Apply" to help better find the category if there are a lot of product categories in my Orchard E-Commerce Website. In this sample there are only 3 :) You get similar search functionality with the current Content Picker by enabling Admin Content Search, but you can't filter the Admin Search by content type, making it less elegant.
I found the Kayaks Category for the Peekaboo Product. Once I choose "Select" I get the familiar Content Picker UI and the need to save my changes now that the proper category has been chosen.
There you have it. A few hours on a lazy Saturday morning and we have built a new Orchard Module that includes a feature-rich Content Picker Field that includes content type filtering and search functionality. I suspect the Content Picker will add similar functionality in the near future. If you haven't played with Orchard 1.5 and the new Content Picker, do so now :)