Exemplo n.º 1
0
    public TemplateDisplay?GetScaffold(int id)
    {
        //empty default
        var dt = new Template(_shortStringHelper, string.Empty, string.Empty)
        {
            Path = "-1"
        };

        if (id > 0)
        {
            ITemplate?master = _fileService.GetTemplate(id);
            if (master != null)
            {
                dt.SetMasterTemplate(master);
            }
        }

        var             content  = _defaultViewContentProvider.GetDefaultFileContent(dt.MasterTemplateAlias);
        TemplateDisplay?scaffold = _umbracoMapper.Map <ITemplate, TemplateDisplay>(dt);

        if (scaffold is not null)
        {
            scaffold.Content = content;
        }

        return(scaffold);
    }
Exemplo n.º 2
0
    public static string GetDefaultFileContent(string?layoutPageAlias = null, string?modelClassName = null, string?modelNamespace = null, string?modelNamespaceAlias = null)
    {
        IDefaultViewContentProvider viewContentProvider =
            StaticServiceProvider.Instance.GetRequiredService <IDefaultViewContentProvider>();

        return(viewContentProvider.GetDefaultFileContent(layoutPageAlias, modelClassName, modelNamespace, modelNamespaceAlias));
    }
Exemplo n.º 3
0
        private string EnsureInheritedLayout(ITemplate template)
        {
            var design = template.Content;

            if (string.IsNullOrEmpty(design))
            {
                design = _defaultViewContentProvider.GetDefaultFileContent(template.MasterTemplateAlias);
            }

            return(design);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Used to check if a template is being created based on a document type, in this case we need to
        /// ensure the template markup is correct based on the model name of the document type
        /// </summary>
        public void Handle(TemplateSavingNotification notification)
        {
            if (_config.ModelsMode == ModelsMode.Nothing)
            {
                return;
            }

            // Don't do anything if we're not requested to create a template for a content type
            if (notification.CreateTemplateForContentType is false)
            {
                return;
            }

            // ensure we have the content type alias
            if (notification.ContentTypeAlias is null)
            {
                throw new InvalidOperationException("ContentTypeAlias was not found on the notification");
            }

            foreach (ITemplate template in notification.SavedEntities)
            {
                // if it is in fact a new entity (not been saved yet) and the "CreateTemplateForContentType" key
                // is found, then it means a new template is being created based on the creation of a document type
                if (!template.HasIdentity && string.IsNullOrWhiteSpace(template.Content))
                {
                    // ensure is safe and always pascal cased, per razor standard
                    // + this is how we get the default model name in Umbraco.ModelsBuilder.Umbraco.Application
                    var alias     = notification.ContentTypeAlias;
                    var name      = template.Name; // will be the name of the content type since we are creating
                    var className = UmbracoServices.GetClrName(_shortStringHelper, name, alias);

                    var modelNamespace = _config.ModelsNamespace;

                    // we do not support configuring this at the moment, so just let Umbraco use its default value
                    // var modelNamespaceAlias = ...;
                    var markup = _defaultViewContentProvider.GetDefaultFileContent(
                        modelClassName: className,
                        modelNamespace: modelNamespace /*,
                                                        * modelNamespaceAlias: modelNamespaceAlias*/);

                    // set the template content to the new markup
                    template.Content = markup;
                }
            }
        }
Exemplo n.º 5
0
        public TemplateDisplay GetScaffold(int id)
        {
            //empty default
            var dt = new Template(_shortStringHelper, string.Empty, string.Empty);

            dt.Path = "-1";

            if (id > 0)
            {
                var master = _fileService.GetTemplate(id);
                if (master != null)
                {
                    dt.SetMasterTemplate(master);
                }
            }

            var content  = _defaultViewContentProvider.GetDefaultFileContent(layoutPageAlias: dt.MasterTemplateAlias);
            var scaffold = _umbracoMapper.Map <ITemplate, TemplateDisplay>(dt);

            scaffold.Content = content;
            return(scaffold);
        }