Adding image and link to my ContentPart

Topics: Customizing Orchard, General
Dec 1, 2013 at 7:53 PM
I am trying to write my first custom module which would rotate a set of banners in the zone. Banner consist of image, text and URL to navigate to when clicked.
To address this I have created a new BannerPart (contentPart) that has following properties:
  • ImagePath
  • LinkUrl
  • Title
My question is how I can use MediaLibraryPicker allow choosing image from the library and get its path when picked?
Another thing that I was not able to find is "registered Url picker" - something that provides list of all routable urls in the CMS. Is there something like this available?

Thank you!
Dec 2, 2013 at 12:51 AM
Ok, I have figured out that I can add MediaLibraryPickerField to my ContentPart and it shows up when I add/edit contentItem.
However in my driver's Editor POST handler when I try to access values from MediaLibraryPickerField I get Ids property populated, but MediaParts - this is where actual image Url lives - is throwing NullObjectReference exception. It appears that _contentItems member of MediaLibraryPickerField is null, even although it is assigned value from MedialLibraryPickerFieldHandler (I have stopped in debugger and confirmed that it does assign value to this member).

Am I missing something?

BTW, second questions still stands, I am not sure how to get all routable Url's.

Dec 3, 2013 at 9:34 AM
I have figured out, that MediaParts are only populated during GET, not POST and in fact I should not really care about them as Orchard persists that information in its own way.
However lack of any responses/comments/suggestions from community is making me wonder if I picked right CMS...
Anyone can comment on their experiences with getting support with Orchard?
Marked as answer by dae01 on 12/3/2013 at 1:34 AM
Dec 3, 2013 at 9:42 AM
Glad to hear you figured it out.
Regarding your second question, could you give a little more context to what exactly you mean by a list of routable URLs?
Do you mean a list of URLs where each URL points to a published content item?
Dec 3, 2013 at 10:30 AM
Edited Dec 3, 2013 at 10:32 AM
Thanks for your reply.

You are correct, I need a list of URLs to all published content items.
My understanding is that I am after all content items that have Autoroute or Route field/part present (am I correct?)

Is it something that can be achieved easily?
Dec 3, 2013 at 11:32 AM
I see. Yes, essentially you would use the IContentManager to get a list of all published content items that have the AutoroutePart attached:
var allContentItems = _contentManager.Query<AutoroutePart>();
If you have a lot of content items, you might want to query one page of data at a time. For that you could use the Slice method:
var page1OfContentItems = _contentManager.Query<AutoroutePart>().Slice(0, 50); // Get the first page of 50 items
var page2OfContentItems = _contentManager.Query<AutoroutePart>().Slice(1, 50); // Get the second page of 50 items
If you don't want to code, simply use a Query and a Projection.
Marked as answer by dae01 on 12/3/2013 at 2:13 PM
Dec 3, 2013 at 10:14 PM
Thank you, this is exactly what I was after!