// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { //order of events important: //Add the Composed Look Files - declaratively optional //Add the Master Page – Add a custom master page //Create a new Composed Look item //Apply the Master Page – //Apply the Composed Look(aka.Theme) //Update the Current Composed Look Item //NOte that subsites get spfont and spcolor from composed look, but not master page; must explicitly set properties on SPWeb to get master page from parent without publishing feature SPSecurity.RunWithElevatedPrivileges(delegate() { var site = properties.Feature.Parent as SPSite; var masterPageName = properties.Definition.Properties["MasterPage"].Value; if (site != null) { var topWeb = site.RootWeb; var masterUrl = new SPFieldUrlValue(); var webAppRelativePath = BrandingHelper.WebAppPath(topWeb, site); //apply everything to TopWeb first to get handle on master page for feature activation masterUrl.Url = webAppRelativePath + catalogMasterPage + masterPageName; var themeUrl = new SPFieldUrlValue(); var fontUrl = new SPFieldUrlValue(); themeUrl.Url = webAppRelativePath + CustomBranding.DeployComposedLookSiteNavEventReceiver_FeatureActivated__catalogs_theme_15_CustomLOGO_spcolor; fontUrl.Url = webAppRelativePath + CustomBranding.DeployComposedLookSiteNavEventReceiver_FeatureActivated__catalogs_theme_15_fontscheme002_spfont; //important: update master page after creating item for composed look in list BrandingHelper.CreateComposedLookListItem(topWeb, customLookCustom, masterUrl, themeUrl, fontUrl); topWeb.Update(); //Open web theme only on rootWeb BrandingHelper.ApplyMasterPageToRootWeb(topWeb, webAppRelativePath, catalogMasterPage, masterPageName); var theme = BrandingHelper.ApplyThemeToRootWeb(topWeb, webAppRelativePath, customLookCustom, themeUrl, fontUrl); BrandingHelper.UpdateCurrentComposedLookListItem(topWeb, customLookCustom, masterUrl, themeUrl, fontUrl); //activate ProvisionWebTheme //BrandingHelper.ActivateProvisionWebThemeFeature(site, guidCustom); BrandingHelper.ActivateProvisionWebThemeFeature(site, guidProvisionWebTheme); topWeb.Update(); // Enumerate through each site and apply branding. foreach (SPWeb currentWeb in site.AllWebs) { if (currentWeb.Url != topWeb.Url) { //must apply master page in this order-after create composed look list item currentWeb.MasterUrl = webAppRelativePath + catalogMasterPage + masterPageName; currentWeb.CustomMasterUrl = webAppRelativePath + catalogMasterPage + masterPageName; currentWeb.SiteLogoUrl = webAppRelativePath + catalogMasterPage + CustomBranding.ProvisionSiteThemeEventReceiver_FeatureActivated_Custom_SP2013_LOGO_png; currentWeb.Update(); using (new CustomPerformanceTimerLogger("DeployedComposedLooktoSubsites", currentWeb.Url.ToString())) { BrandingHelper.ApplyComposedLook(theme, currentWeb); } //good practice in this type of loop with ApplyTo method currentWeb.Dispose(); } } topWeb.AllowUnsafeUpdates = false; } }); }
// Uncomment the method below to handle the event raised after a feature has been activated. public override void FeatureActivated(SPFeatureReceiverProperties properties) { //order of events important: //Add the Composed Look Files - declaratively optional //Add the Master Page – Add a custom master page //Create a new Composed Look item //Apply the Master Page – //Apply the Composed Look(aka.Theme) //Update the Current Composed Look Item SPSecurity.RunWithElevatedPrivileges(delegate() { var site = properties.Feature.Parent as SPSite; var masterPageName = properties.Definition.Properties["MasterPage"].Value; if (site != null) { //SPFieldUrlValue bgImageURL = new SPFieldUrlValue(); var topWeb = site.RootWeb; var masterUrl = new SPFieldUrlValue(); var webAppRelativePath = BrandingHelper.WebAppPath(topWeb, site); //apply everything to TopWeb first to get handle on master page for feature activation masterUrl.Url = webAppRelativePath + catalogMasterPage + masterPageName; var themeUrl = new SPFieldUrlValue(); var fontUrl = new SPFieldUrlValue(); themeUrl.Url = webAppRelativePath + AEPBranding.DeployComposedLookSiteNavEventReceiver_FeatureActivated__catalogs_theme_15_AEPHQAMC_spcolor; fontUrl.Url = webAppRelativePath + AEPBranding.DeployComposedLookSiteNavEventReceiver_FeatureActivated__catalogs_theme_15_fontscheme002_spfont; //get web theme var themeFile = topWeb.GetFile(themeUrl.Url); var fontSchemeFile = topWeb.GetFile(fontUrl.Url); //important: update master page after creating item for composed look in list BrandingHelper.CreateComposedLookListItem(topWeb, customLookAep, masterUrl, themeUrl, fontUrl); topWeb.Update(); //Open web theme only on rootWeb BrandingHelper.ApplyMasterPageToRootWeb(topWeb, webAppRelativePath, catalogMasterPage, masterPageName); var theme = BrandingHelper.ApplyThemeToRootWeb(topWeb, webAppRelativePath, customLookAep, themeUrl, fontUrl); BrandingHelper.UpdateCurrentComposedLookListItem(topWeb, customLookAep, masterUrl, themeUrl, fontUrl); //activate ProvisionWebTheme //BrandingHelper.ActivateProvisionWebThemeFeature(site, guidAEP); BrandingHelper.ActivateProvisionWebThemeFeature(site, guidProvisionWebTheme); topWeb.Update(); // Enumerate through each site and apply branding. foreach (SPWeb currentWeb in site.AllWebs) { if (currentWeb.Url != topWeb.Url) { //must apply master page in this order-after create composed look list item currentWeb.MasterUrl = webAppRelativePath + catalogMasterPage + masterPageName; currentWeb.CustomMasterUrl = webAppRelativePath + catalogMasterPage + masterPageName; currentWeb.SiteLogoUrl = webAppRelativePath + catalogMasterPage + AEPBranding.ProvisionSiteThemeEventReceiver_FeatureActivated_AEP_HQAMC_HQAMC_png; currentWeb.Update(); BrandingHelper.ApplyComposedLook(theme, currentWeb); //good practice in this type of loop with ApplyTo method currentWeb.Dispose(); } } topWeb.AllowUnsafeUpdates = false; } }); }