Need to hide a field on Edit and SummaryAdmin for a Custom Part

Topics: Customizing Orchard, Writing modules
Jul 17, 2014 at 6:14 PM
I have a custom part called Event (EventPart). It has a PartRecord with three fields:
Website (string)
StartDate (datetime)
EndDate (datetime)

I have three custom types - Race, Store Event, Community Event. All three use the Event part.

Here's the important part: for a Race and Community Event, I will use the Website property on the EventPart. On the "Store Event" type, I will not use it, so I want to suppress it from showing up during Content Item creation.

I have a Driver and have overridden the "Edit" view for my EventPart to enter my three properties Website, StartDate, and EndDate.

I'm trying to figure out the best way to suppress the "Website" property and am not having much luck. If I try and figure out the ContentType from the Edit override, I feel like I'm putting logic into my view.

I'm really looking for some best practices guidance here - what's my best course of action?
Jul 18, 2014 at 9:14 PM
Clearly, this has perplexed the entire board, so I'll tell you the road I'm going down. ;-)

I removed the Website field from the database and, instead, added a ContentField to hold the Website data. Here's what's in my Migration:
.WithField("Website", f => f
                        .OfType("InputField").WithDisplayName("Website URL")
                        .WithSetting("InputFieldSettings.Type", "Url")
                        .WithSetting("InputFieldSettings.Title", "Website URL")
                        .WithSetting("InputFieldSettings.Hint", "If the event has a website (not hosted here), enter it's URL address.")
                        .WithSetting("InputFieldSettings.Required", "False")
                        .WithSetting("InputFieldSettings.AutoFocus", "False")
                        .WithSetting("InputFieldSettings.AutoComplete", "False")
                        .WithSetting("InputFieldSettings.Placeholder", "Enter external website URL here")
                        .WithSetting("InputFieldSettings.EditorCssClass", "event-website-url")
                        .WithSetting("InputFieldSettings.MaxLength", "100")
                    )
That will render an Input_Field shape. Since it's my only Input_Field shape, I can hide it in Placement for the Content Types that don't apply, like this:
<Match ContentType="StoreEvent">
    <Place Fields_Input="-"></Place>
  </Match>
This opens the doors another potential problem, though, where perhaps I have two InputFields on a Content Part. How can I distinguish between them? I know I can add an alternate, but I was hoping to avoid having to query the content type from a view. Thoughts?
Jul 19, 2014 at 4:25 AM
Edited Jul 19, 2014 at 4:26 AM
You could have simply used the placement.info file to set an alternate template which hides the web site when editing the Store Event type. Without changing the parts.
Jul 19, 2014 at 4:32 AM
I don't think that's the case. The Website field was part of a ContentRecord and was a field in the database, so my Edit override (View) was what took case of rendering the edit field. No shape is automatically created for me to render that field, so there was no way to "find" it via placement.info. Now that I've converted it to a ContentField, it renders a shape and now I can use placement.info like I did and like you recommend.
Jul 19, 2014 at 9:08 AM
I use this since years