ContentTypePicker Not Filtering on Content Types


I am pretty excited about this change, since I can stop shipping my own version of this feature. It's not working as expected, however, which may be a bug or a misunderstanding on my part.

Essentially, when I specify filtering on a Content Type it does not work. It only works when I filter on a Content Part attached to the Content Type. This code seems questionable as it won't really work unless there is a Content Part attached to a Content Type with the same name. Lines 74 - 84 in AdminController:
IEnumerable<ContentTypeDefinition> contentTypes;
if (settings != null && !String.IsNullOrEmpty(settings.DisplayedContentTypes)) {
    var rawTypes = settings.DisplayedContentTypes.Split(new[] {',', ' '}, StringSplitOptions.RemoveEmptyEntries).ToList();
    contentTypes = _contentDefinitionManager
        .Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)))
else {
    contentTypes = GetCreatableTypes(false).ToList();
This line in particular makes an assumption around Content Parts.
.Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)))
If I create several Content Types of type "Product", with a TitlePart, and then have the Content Type Picker on the "Page" Content Type filter on "Product", it does not work. However, if I create a "Product" Content Part and then attach it to the "Product" Content Type, it works. Is this expected? I need to do both?




DavidHayden wrote Feb 15, 2013 at 3:22 PM

I meant to save "several content items of type Product"



DavidHayden wrote Mar 2, 2013 at 4:26 AM

My apologies that the report above is difficult to understand. Now that I look at it again it seems difficult to understand. Here is the problem and how I fixed it in my own code.

The problem with the Content Type Filtering in the Content Picker as it is now written is that it assumes a ContentPart to be attached to the ContentType with the same name. This is correct if someone has added a field to the Content Type, but not if a person has not. So, we need to re-write the Where selector so that it looks not just as parts for the same name, but the name of the Content Type, too.

Thus this:
.Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)))
.Where(x => x.Parts.Any(p => rawTypes.Contains(p.PartDefinition.Name)) || rawTypes.Contains(x.Name))
Make this change and it works like a champ.

Hope this helps.


sebastienros wrote Mar 4, 2013 at 7:04 PM

Fixed in changeset aacf07cb7b5f

jimitndiaye wrote Jun 19, 2013 at 4:24 PM

Is this merged in the 1.x branch yet? Trying to find this commit but can't find it. Desparately need content type filtering.

BertrandLeRoy wrote Jun 20, 2013 at 1:58 AM

Yes. See the comment right above yours.

sfmskywalker wrote Mar 28, 2014 at 12:28 AM

Fixed in changeset 03663dfee43db8f17421d8470ca02c0b337a257a