Don't repeat the code to check for and create a template
This commit is contained in:
@@ -232,20 +232,7 @@ namespace Umbraco.Web.Editors
|
||||
// create item doctype template
|
||||
if (collectionItemCreateTemplate)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(itemDocType.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(itemDocType.Alias, itemDocType.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => itemDocType.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
var template = CreateTemplateForContentType(itemDocType.Alias, itemDocType.Name);
|
||||
itemDocType.SetDefaultTemplate(template);
|
||||
}
|
||||
|
||||
@@ -266,20 +253,7 @@ namespace Umbraco.Web.Editors
|
||||
// create collection doctype template
|
||||
if (collectionCreateTemplate)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(collectionDocType.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(collectionDocType.Alias, collectionDocType.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => collectionDocType.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
var template = CreateTemplateForContentType(collectionDocType.Alias, collectionDocType.Name);
|
||||
collectionDocType.SetDefaultTemplate(template);
|
||||
}
|
||||
|
||||
@@ -296,8 +270,6 @@ namespace Umbraco.Web.Editors
|
||||
allowedCts.Add(new ContentTypeSort(collectionDocType.Id, allowedCts.Count()));
|
||||
parentCt.AllowedContentTypes = allowedCts;
|
||||
Services.ContentTypeService.Save(parentCt);
|
||||
} else
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -320,19 +292,7 @@ namespace Umbraco.Web.Editors
|
||||
//create a default template if it doesnt exist -but only if default template is == to the content type
|
||||
if (ctSave.DefaultTemplate.IsNullOrWhiteSpace() == false && ctSave.DefaultTemplate == ctSave.Alias)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(ctSave.Alias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => ctSave.Alias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
var template = CreateTemplateForContentType(ctSave.Alias, ctSave.Name);
|
||||
|
||||
// If the alias has been manually updated before the first save,
|
||||
// make sure to also update the first allowed template, as the
|
||||
@@ -362,6 +322,26 @@ namespace Umbraco.Web.Editors
|
||||
return display;
|
||||
}
|
||||
|
||||
private ITemplate CreateTemplateForContentType(string contentTypeAlias, string contentTypeName)
|
||||
{
|
||||
var template = Services.FileService.GetTemplate(contentTypeAlias);
|
||||
if (template == null)
|
||||
{
|
||||
var tryCreateTemplate = Services.FileService.CreateTemplateForContentType(contentTypeAlias, contentTypeName);
|
||||
if (tryCreateTemplate == false)
|
||||
{
|
||||
Logger.Warn<ContentTypeController>(
|
||||
"Could not create a template for the Content Type: {0}, status: {1}",
|
||||
() => contentTypeAlias,
|
||||
() => tryCreateTemplate.Result.StatusType);
|
||||
}
|
||||
|
||||
template = tryCreateTemplate.Result.Entity;
|
||||
}
|
||||
|
||||
return template;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns an empty content type for use as a scaffold when creating a new type
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user