IWidgetService.GetZones() vs IWidgetService.GetZones(currentTheme)

Topics: Customizing Orchard
Mar 11, 2015 at 5:06 PM
Edited Mar 11, 2015 at 5:08 PM
I'm working on a notification activity that allows the user to specify which zone the notification should appear in. I ran into a problem when there is no theme active or the theme has no registered zones (I don't really understand how that happens). I currently am just hard-coding the form for the activity to have some of the standard zones when no theme is active and if a theme is active but the GetZones(currentTheme) returns with no zones I used the results from GetZones(). This appears to work, but I'm wondering if there is a better way of doing this/if my way will cause problems somewhere down the road. Thank you.

Also what is the difference between the two GetZones functions?
        public void Describe(DescribeContext context)
        {
            ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();
            if (currentTheme == null)
            {
                context.Form("ActivityCustomNotify",
                    shape => Shape.Form(
                    Id: "ActivityCustomNotify",
                    _Type: Shape.SelectList(
                        Id: "notification", Name: "Notification",
                        Title: T("Notification type"),
                        Description: T("Select what type of notification should be displayed."))
                        .Add(new SelectListItem { Value = "Calculator", Text = T("Calculator").Text })
                        .Add(new SelectListItem { Value = "SiteCustom", Text = T("Site Custom").Text })
                        .Add(new SelectListItem { Value = "Information", Text = T("Information").Text })
                        .Add(new SelectListItem { Value = "Warning", Text = T("Warning").Text })
                        .Add(new SelectListItem { Value = "Error", Text = T("Error").Text }),
                     _Zone: Shape.SelectList(
                        Id: "zone", Name: "Zone",
                        Title: T("Zone"),
                        Description: T("The zone to display the message in"))
                        .Add(new SelectListItem { Value = "BeforeMain", Text = T("BeforeMain").Text })
                        .Add(new SelectListItem { Value = "Featured", Text = T("Featured").Text })
                        .Add(new SelectListItem { Value = "AsideFirst", Text = T("AsideFirst").Text })
                        .Add(new SelectListItem { Value = "AsideSecond", Text = T("AsideSecond").Text })
                        .Add(new SelectListItem { Value = "Messages", Text = T("Messages").Text })
                        .Add(new SelectListItem { Value = "BeforeContent", Text = T("BeforeContent").Text })
                        .Add(new SelectListItem { Value = "Content", Text = T("Content").Text })
                        .Add(new SelectListItem { Value = "AfterContent", Text = T("AfterContent").Text })
                        .Add(new SelectListItem { Value = "AfterMain", Text = T("AfterMain").Text }),
                    _Message: Shape.Textbox(
                        Id: "message", Name: "Message",
                        Title: T("Message"),
                        Description: T("The notification message to display."),
                        Classes: new[] { "text medium", "tokenized" })
                    )
                );
            }
            else
            {
                IEnumerable<string> allZones = _widgetsService.GetZones();
                IEnumerable<string> currentThemesZones = _widgetsService.GetZones(currentTheme);

                if(!currentThemesZones.Any())
                {
                    currentThemesZones = allZones;
                }

                Func<IShapeFactory, dynamic> form =
                    shape =>
                    {
                        var f = Shape.Form(
                            Id: "ActivityCustomNotify",
                            _Type: Shape.SelectList(
                                Id: "notification", Name: "Notification",
                                Title: T("Notification type"),
                                Description: T("Select what type of notification should be displayed."))
                                .Add(new SelectListItem { Value = "Calculator", Text = T("Calculator").Text })
                                .Add(new SelectListItem { Value = "SiteCustom", Text = T("Site Custom").Text })
                                .Add(new SelectListItem { Value = "Information", Text = T("Information").Text })
                                .Add(new SelectListItem { Value = "Warning", Text = T("Warning").Text })
                                .Add(new SelectListItem { Value = "Error", Text = T("Error").Text }),
                            _Zone: Shape.SelectList(
                                Id: "zone", Name: "Zone",
                                Title: T("Zone"),
                                Description: T("The zone to display the message in")),
                            _Message: Shape.Textbox(
                                Id: "message", Name: "Message",
                                Title: T("Message"),
                                Description: T("The notification message to display."),
                                Classes: new[] { "text medium", "tokenized" })
                            );

                        foreach (string zone in currentThemesZones)
                        {
                            f._Zone.Add(new SelectListItem { Value = zone, Text = T(zone).Text });
                        }

                        return f;
                    };

                context.Form("ActivityCustomNotify", form);
            }
        }