OrchardCMS / Orchard

Orchard is a free, open source, community-focused Content Management System built on the ASP.NET MVC platform.
https://orchardproject.net
BSD 3-Clause "New" or "Revised" License
2.37k stars 1.12k forks source link

Not possible to use user-properties in tokens for contentpickerfield #4259

Open orchardbot opened 10 years ago

orchardbot commented 10 years ago

hkui created: https://orchard.codeplex.com/workitem/20430

When using a contentpickerfield, it is not possible to use user properties on the selected user.

For example I have a contentpickerfield that has a user selected, then I want to use this token: Content.CommentedOn.Fields.PageWithComments.SomeUserContentPicker.Content.Email

It doesn't work. The Email-token is assigned to "User", but what's returned on the ContentPickerField is a "Content".

Therefore I modified: Orchard.ContentPicker.Tokens.ContentPickerFieldTokens.Evaluate(): context.For("ContentPickerField") .Token("Content", (Func<ContentPickerField, object>)(field => field.Ids[0])) .Chain("Content", "Content", (Func<ContentPickerField, object>)(field => _contentManager.Get(field.Ids[0]))) .Token("User", (Func<ContentPickerField, object>)(field => field.Ids[0])) .Chain("User", "User", (Func<ContentPickerField, object>)(field => _contentManager.Get(field.Ids[0]).As())) ;

The last Token() and Chain() call are added by me.

Now I can do: Content.CommentedOn.Fields.PageWithComments.SomeUserContentPicker.User.Email

I propose this to be added into the Orchard.ContentPicker module. Or maybe it's already possible by doing it another way, but I'm not sure how. If so, can anyone please tell me?

orchardbot commented 10 years ago

hkui commented:

Topic: https://orchard.codeplex.com/discussions/501444

orchardbot commented 9 years ago

@sebastienros commented:

I would suggest instead to create a new token like "AsUser" which would be chained from a Content context and return a User context. This way it could be applied to tokens which are not only from ContentPickerField.

Your string would become Content.CommentedOn.Fields.PageWithComments.SomeUserContentPicker.Content.AsUser.Email