Example #1
0
        protected bool CompleteInit(IBlockBuilder rootBuilder, IBlockIdentifier blockId, int blockNumberUnsureIfNeeded)
        {
            var wrapLog = Log.Call <bool>();

            ParentId       = Context.Module.Id;
            ContentBlockId = blockNumberUnsureIfNeeded;

            Log.Add($"parent#{ParentId}, content-block#{ContentBlockId}, z#{ZoneId}, a#{AppId}");

            // 2020-09-04 2dm - new change, moved BlockBuilder up so it's never null - may solve various issues
            // but may introduce new ones
            BlockBuilder = new BlockBuilder(rootBuilder, this, Log);

            // If specifically no app found, end initialization here
            // Means we have no data, and no BlockBuilder
            if (AppId == AppConstants.AppIdNotFound || AppId == Eav.Constants.NullId)
            {
                DataIsMissing = true;
                return(wrapLog("stop: app & data are missing", true));
            }

            // If no app yet, stop now with BlockBuilder created
            if (AppId == Eav.Constants.AppIdEmpty)
            {
                var msg = $"stop a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}";
                return(wrapLog(msg, true));
            }


            Log.Add("Real app specified, will load App object with Data");

            // Get App for this block
            Log.Add("About to create app");
            App = Context.ServiceProvider.Build <App>()
                  .PreInit(Context.Site)
                  .Init(this, Context.ServiceProvider.Build <AppConfigDelegate>().Init(Log).BuildForNewBlock(Context, this), Log);
            Log.Add("App created");

            // note: requires EditAllowed, which isn't ready till App is created
            var cms = Context.ServiceProvider.Build <CmsRuntime>().Init(App, Context.UserMayEdit, Log);

            Configuration = cms.Blocks.GetOrGeneratePreviewConfig(blockId);

            // handle cases where the content group is missing - usually because of incomplete import
            if (Configuration.DataIsMissing)
            {
                DataIsMissing = true;
                App           = null;
                return(wrapLog($"DataIsMissing a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}", true));
            }

            // use the content-group template, which already covers stored data + module-level stored settings
            View = new BlockViewLoader(Log).PickView(this, Configuration.View, Context, cms);
            return(wrapLog($"ok a:{AppId}, container:{Context.Module.Id}, content-group:{Configuration?.Id}", true));
        }
Example #2
0
        internal BlockConfiguration GetOrGeneratePreviewConfig(IBlockIdentifier blockId)
        {
            var wrapLog = Log.Call($"get CG or gen preview for grp#{blockId.Guid}, preview#{blockId.PreviewView}");
            // Return a "faked" ContentGroup if it does not exist yet (with the preview templateId)
            var createTempBlockForPreview = blockId.Guid == Guid.Empty;

            Log.Add($"{nameof(createTempBlockForPreview)}:{createTempBlockForPreview}");
            var result = createTempBlockForPreview
                ? new BlockConfiguration(blockId.PreviewView, CmsRuntime, Log)
                : GetBlockConfig(blockId.Guid);

            wrapLog(null);
            return(result);
        }