Override parts in a custom form

Topics: Customizing Orchard, Writing themes
Dec 19, 2014 at 2:27 PM

Today I created a content part called NewReservationPart. I added this part to a new contenttype called NewReservation along with the CommonPart. Finally I created a custom form using my NewReservation type.

When the form gets displayed on the website I noticed that the driver is using the Editor call and not the Display. Why is this? I’m also curious if anybody can tell me why there is an Editor update method but no Display update method.

Also, how should I override my content part NewReservationPart shape? Normally I wouldn't want to override Editor/Admin templates in a theme, but for this specific case I have to. A basic version is in my module (not tied to a specific implementation like using bootstrap and/or angular). In my Theme is the fancy version.

Trying to override the NewReservationPart in my theme I looked in the shape alternates list but I only see an alternate that overwrites all the parts with the same shape (including Common).
My current solution is using a IShapeTableProvider listed below. Is this the way to go or is there a better solution?
using Orchard.DisplayManagement.Descriptors;

namespace HZS.Reservation.Shapes
    public class AlternatesProvider : IShapeTableProvider
        public void Discover(ShapeTableBuilder builder)
                .OnDisplaying(displaying =>
                    if (displaying.Shape.TemplateName == "Parts/NewReservation")
Dec 21, 2014 at 9:02 AM
Edited Dec 21, 2014 at 9:02 AM
Never mind.. I was thinking to complicated with all the Alternate shapes etc.. Just create a EditorTemplates/Parts/Newreservation.cshtml in the theme's view folder did the trick to style just the part for a custom form.

I am still curious though why custom forms uses the drivers Editor methods. Does this has the do with the fact that the model of Editor template is the modelpart class instead of a Shape (drivers display way of rendering things)?
Dec 22, 2014 at 2:11 AM
Edited Dec 22, 2014 at 2:23 AM
When you create a CustomForm, you associate it with a custom ContentType that you have first created (e.g NewReservation). So, when you display your form, it's a new content item (of your custom type) that is created, and that why it's the editor shape (of this new content item) that is used...

If you enable the Alias UI module, you will see that your route alias (e.g new-reservation) is associated with a route like that: Orchard.CustomForms/Item/Create/{id}, these route infos are provided in CustomFormPartHandler.cs... So, take a look in ItemController.cs, in the Create Action (or, if the form is via a widget, in CustomFormPartDriver.cs, in the Display() method), where a new item of your customForm.ContentType (or part.ContentType) is created, and where the content manager BuildEditor() is invoked on this new content item...

In the 1.x version, it's different with the new DynamicForms module that I just began to try. For example, in the Alias UI you will see something like that: Contents/Item/Display/{id}. Note the Display in place of the Create action

Marked as answer by Jwheuvel on 12/21/2014 at 11:48 PM
Dec 22, 2014 at 6:48 AM
Thanks for the great insight.. It all makes more sense if you get to know the why behind the magic :-)

I'm a fairly decent .NET developer but do find myself struggling to grasp all the bits that makes Orchard spin.