Debugging an unused EditorTemplate

Topics: Customizing Orchard
Feb 13, 2012 at 5:24 PM

Just started my first module. I took a copy of the Contrib.DateTimeField module to enhance it to a version where there's a DateTimeRange (with start and end).

All is working fine; Module is recognized and feature is enabled. Created a content type with the field and the settings editor shows up nicely. However, when I create a content item using this field, I don't get to see the editor template for it. In other words, I don't see my field when creating a content item.

I figured, let's debug this thing, but it goes through the heart of Orchard and passes a lot of code that I don't understand. It did reach the Driver's Editor method, but from there onward I'm in the dark.

So, I was wondering what is the best way to move forward. I probably did a typo (although I triple checked it) but how can I "debug" this? are there any points in the code (after the Driver's Editor method") where I can check and follow the flow?

thnx

Feb 13, 2012 at 5:39 PM

You might be missing an entry in placement.info 

Feb 14, 2012 at 8:41 AM

Well, I used the same Placement info as the Contrib.DateTimeField ie:

<Placement>
  <Place Fields_Line20_DateTimeRange_Edit="Content:2.5"/>

  <Match DisplayType="SummaryAdmin">
    <Place Fields_Line20_DateTimeRange="Content"/>
  </Match>

  <Place Fields_Line20_DateTimeRange="Content:after"/>
</Placement>

and I have the following views:

\Views\DefinitionTemplates\DateTimeRangeFieldSettings.cshtml
\Views\EditorTemplates\Fields\Line20.DateTimeRange.cshtml
\Views\Fields\Line20.DateTimeRange.cshtml

Coordinator
Feb 14, 2012 at 8:45 AM

So the debugger hits the field's driver? Can you show the Editor code in that driver?

Feb 14, 2012 at 10:09 AM
Edited Feb 14, 2012 at 10:11 AM

Sure; 

        protected override DriverResult Editor(ContentPart part, Fields.DateTimeRangeField field, dynamic shapeHelper) {

            var settings = field.PartFieldDefinition.Settings.GetModel<DateTimeRangeFieldSettings>();
            var startValue = field.StartDateTime;
            var endValue = field.EndDateTime;

            var viewModel = new DateTimeRangeFieldViewModel {
                Name = field.Name,
                StartDate = startValue.HasValue ? startValue.Value.ToLocalTime().ToShortDateString() : "",
                StartTime = startValue.HasValue ? startValue.Value.ToLocalTime().ToShortTimeString() : "",
                EndDate = endValue.HasValue ? endValue.Value.ToLocalTime().ToShortDateString() : "",
                EndTime = endValue.HasValue ? endValue.Value.ToLocalTime().ToShortTimeString() : "",
                ShowDate = settings.Display == DateTimeRangeFieldDisplays.DateAndTime || settings.Display == DateTimeRangeFieldDisplays.DateOnly,
                ShowTime = settings.Display == DateTimeRangeFieldDisplays.DateAndTime || settings.Display == DateTimeRangeFieldDisplays.TimeOnly

            };

            return ContentShape("Fields_Line20_DateTimeRange_Edit", // this is just a key in the Shape Table
                () => shapeHelper.EditorTemplate(TemplateName: "Fields/Line20.DateTimeRange", Model: viewModel, Prefix: GetPrefix(field, part)));
        }
Feb 14, 2012 at 10:13 AM

I must say that I did ran the code before with a different key name of the shape table. It was only afterwards that I noticed to change that as well.

Feb 14, 2012 at 1:14 PM

Pfeew, after hours of search I found the issue. Basically I did not had all the files defined in the .csproj file. Not an evident thing when working from WebMatrix... but hey, we learned something :)