diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index 57ad512616..c096b3dc70 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -207,20 +207,20 @@ namespace Umbraco.Core.Models { if (string.IsNullOrWhiteSpace(name)) throw new ArgumentNullOrEmptyException(nameof(name)); + + //fixme - we always need to set the invariant values since these cannot be null! discuss http://issues.umbraco.org/issue/U4-11286 + PublishName = name; + PublishDate = date; - if (culture == null) - { - PublishName = name; - PublishDate = date; - return; + if (culture != null) + { + // private method, assume that culture is valid + + if (_publishInfos == null) + _publishInfos = new Dictionary(StringComparer.OrdinalIgnoreCase); + + _publishInfos[culture] = (name, date); } - - // private method, assume that culture is valid - - if (_publishInfos == null) - _publishInfos = new Dictionary(StringComparer.OrdinalIgnoreCase); - - _publishInfos[culture] = (name, date); } /// diff --git a/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs b/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs index 7f79788091..2e8de4afa4 100644 --- a/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs +++ b/src/Umbraco.Core/Persistence/Repositories/Implement/DocumentRepository.cs @@ -241,7 +241,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (entity.Template == null) entity.Template = entity.ContentType.DefaultTemplate; - entity.Name = FormatInvariantNameValue(entity); + EnsureInvariantNameValues(entity, publishing); // ensure unique name on the same level entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name); @@ -309,7 +309,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement content.PublishedVersionId = content.VersionId; contentVersionDto.Id = 0; contentVersionDto.Current = true; - contentVersionDto.Text = content.Name; + contentVersionDto.Text = content.PublishName; Database.Insert(contentVersionDto); content.VersionId = contentVersionDto.Id; @@ -420,7 +420,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement Database.Execute(Sql().Update(u => u.Set(x => x.Published, false)).Where(x => x.Id == content.PublishedVersionId)); } - entity.Name = FormatInvariantNameValue(entity); + EnsureInvariantNameValues(entity, publishing); // ensure unique name on the same level entity.Name = EnsureUniqueNodeName(entity.ParentId, entity.Name, entity.Id); @@ -1080,33 +1080,38 @@ namespace Umbraco.Core.Persistence.Repositories.Implement #region Utilities /// - /// This ensures that the Name property exists and validates if all names are null + /// This ensures that the Name/PublishName properties are filled in and validates if all names are null /// /// /// - private string FormatInvariantNameValue(IContent content) + private void EnsureInvariantNameValues(IContent content, bool publishing) { + //fixme - if we are saving a variant, we current need to have the invariant name set too, discuss! http://issues.umbraco.org/issue/U4-11286 + //NOTE - this doesn't deal with the PublishName since that is readonly, instead this scenario is dealt with in `Content.SetPublishInfos` + + //validate + if (content.Name.IsNullOrWhiteSpace() && content.Names.Count == 0) - throw new InvalidOperationException("Cannot save content with empty name."); + throw new InvalidOperationException("Cannot save content with an empty name."); + + if (publishing && content.PublishName.IsNullOrWhiteSpace() && content.PublishNames.Count == 0) + throw new InvalidOperationException("Cannot publish content with an empty name."); + + //ensure the invariant Name if (content.Name.IsNullOrWhiteSpace() && content.Names.Count > 0) { - //if we are saving a variant, we current need to have the invariant name set too - //fixme - this needs to be discussed! http://issues.umbraco.org/issue/U4-11286 - var defaultCulture = LanguageRepository.GetDefaultIsoCode(); if (!defaultCulture.IsNullOrWhiteSpace() && content.Names.TryGetValue(defaultCulture, out var cultureName)) { - return cultureName; + content.Name = cultureName; } else { //our only option is to take the first - return content.Names.First().Value; + content.Name = content.Names.First().Value; } } - - return content.Name; } protected override string EnsureUniqueNodeName(int parentId, string nodeName, int id = 0) diff --git a/src/Umbraco.Core/StringExtensions.cs b/src/Umbraco.Core/StringExtensions.cs index afdb4c3646..a399c82f0c 100644 --- a/src/Umbraco.Core/StringExtensions.cs +++ b/src/Umbraco.Core/StringExtensions.cs @@ -1147,7 +1147,8 @@ namespace Umbraco.Core /// The text to filter. /// The safe url segment. public static string ToUrlSegment(this string text) - { + { + if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("message", nameof(text)); return Current.ShortStringHelper.CleanStringForUrlSegment(text); } @@ -1158,7 +1159,10 @@ namespace Umbraco.Core /// The culture. /// The safe url segment. public static string ToUrlSegment(this string text, CultureInfo culture) - { + { + if (string.IsNullOrWhiteSpace(text)) throw new ArgumentException("message", nameof(text)); + if (culture == null) throw new ArgumentNullException(nameof(culture)); + return Current.ShortStringHelper.CleanStringForUrlSegment(text, culture); } diff --git a/src/Umbraco.Web.UI.Client/src/views/content/content.create.controller.js b/src/Umbraco.Web.UI.Client/src/views/content/content.create.controller.js index ace6058b1d..199976f3fa 100644 --- a/src/Umbraco.Web.UI.Client/src/views/content/content.create.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/content/content.create.controller.js @@ -29,9 +29,10 @@ function contentCreateController($scope, } function createBlank(docType) { - $location - .path("/content/content/edit/" + $scope.currentNode.id) - .search("doctype=" + docType.alias + "&create=true"); + $location + .path("/content/content/edit/" + $scope.currentNode.id) + .search("doctype", docType.alias) + .search("create", true); close(); } @@ -69,4 +70,4 @@ angular.module("umbraco").controller("Umbraco.Editors.Content.CreateController", angular.module("umbraco").value("blueprintConfig", { skipSelect: false, allowBlank: true -}); \ No newline at end of file +});