public static IContextOfBlock Init(this IContextOfBlock context, ModuleInfo dnnModule, ILog parentLog) { context.Init(parentLog); ((DnnSite)context.Site).TrySwap(dnnModule); ((DnnModule)context.Module).Init(dnnModule, parentLog); return(InitPageOnly(context)); }
private IView TryToGetTemplateBasedOnUrlParams(IContextOfBlock context, CmsRuntime cms) { var wrapLog = Log.Call <IView>("template override - check"); if (context.Page.Parameters == null) { return(wrapLog("no params", null)); } var urlParameterDict = context.Page.Parameters.ToDictionary(pair => pair.Key?.ToLowerInvariant() ?? "", pair => $"{pair.Key}/{pair.Value}".ToLowerInvariant()); var allTemplates = cms.Views.GetAll(); foreach (var template in allTemplates.Where(t => !string.IsNullOrEmpty(t.UrlIdentifier))) { var desiredFullViewName = template.UrlIdentifier.ToLowerInvariant(); if (desiredFullViewName.EndsWith("/.*")) // match details/.* --> e.g. details/12 { var keyName = desiredFullViewName.Substring(0, desiredFullViewName.Length - 3); if (urlParameterDict.ContainsKey(keyName)) { return(wrapLog("template override - found:" + template.Name, template)); } } else if (urlParameterDict.ContainsValue(desiredFullViewName)) // match view/details { return(wrapLog("template override - found:" + template.Name, template)); } } return(wrapLog("template override - none", null)); }
protected void Init(IContextOfBlock context, IAppIdentity appId, ILog parentLog) { Init(parentLog); Context = context; ZoneId = appId.ZoneId; AppId = appId.AppId; }
/// <summary> /// Create a module-content block /// </summary> /// <param name="ctx"></param> /// <param name="parentLog">a parent-log; can be null but where possible you should wire one up</param> ///// <param name="overrideParams">optional override parameters</param> public BlockFromModule Init(IContextOfBlock ctx, ILog parentLog) { Init(ctx, ctx.Module.BlockIdentifier, parentLog); var wrapLog = Log.Call <BlockFromModule>(); IsContentApp = ctx.Module.IsPrimary; CompleteInit(null, ctx.Module.BlockIdentifier, ctx.Module.Id); return(wrapLog("ok", this)); }
internal IView PickView(IBlock block, IView configView, IContextOfBlock context, CmsRuntime cms) { //View = configView; // skip on ContentApp (not a feature there) or if not relevant or not yet initialized if (block.IsContentApp || block.App == null) { return(configView); } // #2 Change Template if URL contains the part in the metadata "ViewNameInUrl" var viewFromUrlParam = TryToGetTemplateBasedOnUrlParams(context, cms); return(viewFromUrlParam ?? configView); }
/// <summary> /// Generate a delegate which will be used to build the configuration based on a new sxc-instance /// </summary> internal Func <App, IAppDataConfiguration> BuildForNewBlock(IContextOfBlock context, IBlock block) { var showDrafts = context.UserMayEdit; var wrapLog = Log.Call($"showDrafts: {showDrafts}"); wrapLog("ok"); return(appToUse => { // check if we'll use the config already on the sxc-instance, or generate a new one var lookUpEngine = GetConfigProviderForModule(context, appToUse as IApp, block); // return results return new AppDataConfiguration(showDrafts, lookUpEngine); }); }
public static IContextOfBlock InitPageOnly(this IContextOfBlock context) { // Collect / assemble page information var activeTab = (context.Site as Site <PortalSettings>)?.UnwrappedContents?.ActiveTab; context.Page.Init(activeTab?.TabID ?? Eav.Constants.NullId); // the FullUrl will throw an error in DNN search scenarios try { ((Page)context.Page).Url = activeTab?.FullUrl; } catch { /* ignore */ } return(context); }
public JsContextEnvironment(string systemRootUrl, IContextOfBlock ctx) { WebsiteId = ctx.Site.Id; WebsiteUrl = "//" + ctx.Site.Url + "/"; PageId = ctx.Page.Id; PageUrl = ctx.Page.Url; InstanceId = ctx.Module.Id; SxcVersion = Settings.Version.ToString(); SxcRootUrl = systemRootUrl; var userMayEdit = ctx.UserMayEdit; IsEditable = userMayEdit; parameters = ctx.Page.Parameters; }