ContentPickerField for users?? Pick users?

Topics: Administration, Core, Customizing Orchard, General, Installing Orchard, Troubleshooting, Writing modules
Dec 16, 2013 at 1:53 PM
I'm trying to make a content picker field that will allow people to select 1 or more users. The contentpickerfield works for everything, except for users.

What am I doing wrong? I'm setting the filter to "User". That doesn't work. Also tried "UserPart" and even "IUser". But I can't get it to work.

How can I create a contentpickerfield that allows one to select 1 or more users?
Developer
Dec 16, 2013 at 2:03 PM
Perhaps the content picker doesn't list content items whose type's "Creatable" setting is set to false. It sounds like a bug, because if you're able to choose non-creatable types as a filter, you should see items of that type. As a test, try and turn on the "Creatable" option on the User type and see if that changes things. If so, please file a bug.
Dec 16, 2013 at 2:22 PM
If it's not there, you can also try attaching CommonPart to User content type.


Developer
Dec 16, 2013 at 2:28 PM
One can try, but I don't think that's a good idea. Perhaps someone found a way to solve it, but I remember something like stack overflows due to the CommonPart trying to get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, which would now have a Common Part, which would try and get the current user, ... SO.
Dec 16, 2013 at 2:42 PM
That behavior is supposed to be gone, as GregoryHill reported here: https://orchard.codeplex.com/discussions/462649


Dec 16, 2013 at 3:17 PM
I tried to figure that out.

But I turned on "Creatable" and also "Draftable" (just to test); still no results.
It seems to me that "User" is some sort of special content type that does not work like other content types.

For example, when I try to create a user (after marking it creatable), there is no form being shown at all.
Developer
Dec 16, 2013 at 4:22 PM
kassobasi wrote:
That behavior is supposed to be gone, as GregoryHill reported here: https://orchard.codeplex.com/discussions/462649
I didn't know. Good!
Developer
Dec 16, 2013 at 4:24 PM
Perhaps try kassobasi's suggestion.
Dec 16, 2013 at 4:25 PM
Attaching a CommonPart does not help, there's still no users being shown, unfortunately. :-(
Developer
Dec 16, 2013 at 4:32 PM
Edited Dec 16, 2013 at 4:36 PM
Indeed, User is a specific type in a way that it does not contain an editor form (by design - users should be created via Users admin screen only). This is the only difference - besides that it's an ordinary content type.

The reason why you're not able to see users there is because it does not contain a CommonPart. Sorting options require the CommonPartRecord to exist for each displayed item and thus add an implicit inner join.

As Sipke wrote - adding CommonPart to User type is a bad idea, but you can work around this and simply remove the sorting options. It can be found inside Orchard.ContentPicker.Controllers.AdminController.Index - just remove the switch statement.

@hkui Adding a part to a type won't automagically create records for existing items. You need to re-publish every item afterwards.
Dec 16, 2013 at 4:38 PM
But then I'm essentially altering the core of Orchard.

I don't like doing that. What is the better solution? I understand there is some fixing to be done. I can simply create a new module, that contains everything identical to the contentpicker, but then don't rely on the commonpart. However, that's code duplication all over the place.

Is there a better solution?

I've just played a bit with the container and containable, they seem to do something close to what I am looking for, though not completely. Having the content picker also working for users would solve my problem completely.

Maybe we need to fix the admincontroller to be able to determine wether or not the sorting-options should be added? I.e. when a type/part like User (which does not support CommonPart) is used as a filter, do not support sorting.
Developer
Dec 16, 2013 at 4:45 PM
@hkui. Fair point. I guess switching to left outer join should help. Please file a bug and we'll see what can be done.
Dec 16, 2013 at 5:16 PM
Developer
Jan 4, 2014 at 8:26 PM
Edited Jan 4, 2014 at 8:32 PM
So I thought I had a need for similar functionality in the past.
At the time I was a fan of this module https://github.com/webadvanced/Orchard-ContentReference so I based my functionality from there.

So I drafted this module to to do it...
There might be one or two lingering bugs with it, as I chose to go in a different direction to what i was building.
I uploaded it to GitHub here, maybe you can find it useful.

https://github.com/StanleyGoldman/JustAProgrammer.UserPicker

It allows you to specify a projection that returns UserParts and it will display that projection in the editor. It doesnt have a front end display, but those shapes could be provided.