public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { if (builder.Name != "AutoroutePart") { yield break; } var settings = new AutorouteSettings { Patterns = new List <RoutePattern>() }; //get cultures settings.SiteCultures = _cultureManager.ListCultures().ToList(); if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { //TODO need to add validations client and/or server side here // remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); //If there is no default pattern for each culture we set default ones List <RoutePattern> newPatterns = new List <RoutePattern>(); int current = 0; foreach (string culture in settings.SiteCultures) { if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { newPatterns.Add(settings.Patterns[current]); current++; } } else { newPatterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }); _notifier.Warning(T("A default pattern has been added to AutoroutePart")); } } settings.Patterns = newPatterns; // update the settings builder settings.Build(builder); } yield return(DefinitionTemplate(settings)); }
public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { if (builder.Name != "AutoroutePart") { yield break; } var settings = new AutorouteSettings { Patterns = new List <RoutePattern>() }; if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { var defaultPattern = settings.Patterns[settings.DefaultPatternIndex]; // remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); if (patterns.Count == 0) { patterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" }); _notifier.Warning(T("A default pattern has been added to AutoroutePart")); } settings.Patterns = patterns; // search for the pattern which was marked as default, and update its index settings.DefaultPatternIndex = patterns.IndexOf(defaultPattern); // if a wrong pattern was selected and there is at least one pattern, default to first if (settings.DefaultPatternIndex == -1 && settings.Patterns.Any()) { settings.DefaultPatternIndex = 0; } // update the settings builder settings.Build(builder); } yield return(DefinitionTemplate(settings)); }
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { if (builder.Name != "AutoroutePart") yield break; var settings = new AutorouteSettings { Patterns = new List<RoutePattern>() }; if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { var defaultPattern = settings.Patterns[settings.DefaultPatternIndex]; // remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); if (patterns.Count == 0) { patterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}" }); _notifier.Warning(T("A default pattern has been added to AutoroutePart")); } settings.Patterns = patterns; // search for the pattern which was marked as default, and update its index settings.DefaultPatternIndex = patterns.IndexOf(defaultPattern); // if a wrong pattern was selected and there is at least one pattern, default to first if (settings.DefaultPatternIndex == -1 && settings.Patterns.Any()) { settings.DefaultPatternIndex = 0; } // update the settings builder settings.Build(builder); } yield return DefinitionTemplate(settings); }
public void ContentPartAttached(ContentPartAttachedContext context) { if (context.ContentPartName == "AutoroutePart") { //Create pattern and default pattern for each culture installed //get cultures var SiteCultures = _cultureManager.ListCultures().ToList(); //Create Patterns and DefaultPatterns var settings = new AutorouteSettings { Patterns = new List<RoutePattern>() }; List<RoutePattern> newPatterns = new List<RoutePattern>(); List<DefaultPattern> newDefaultPatterns = new List<DefaultPattern>(); foreach (string culture in SiteCultures) { newPatterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }); newDefaultPatterns.Add(new DefaultPattern { Culture = culture, PatternIndex = "0" }); } settings.Patterns = newPatterns; settings.DefaultPatterns = newDefaultPatterns; //Update Settings _contentDefinitionManager.AlterTypeDefinition(context.ContentTypeName, builder => builder.WithPart("AutoroutePart", settings.Build)); //TODO Generate URL's for existing content items //We should provide a global setting to enable/disable this feature } }
private void SetAutorouteSettings(AutorouteSettings autorouteSettings, SettingsDictionary settings) { settings["AutorouteSettings.AllowCustomPattern"] = autorouteSettings.AllowCustomPattern.ToString(); settings["AutorouteSettings.AutomaticAdjustmentOnEdit"] = autorouteSettings.AutomaticAdjustmentOnEdit.ToString(); settings["AutorouteSettings.DefaultPatternIndex"] = autorouteSettings.DefaultPatternIndex.ToString(); settings["AutorouteSettings.PerItemConfiguration"] = autorouteSettings.PerItemConfiguration.ToString(); settings["AutorouteSettings.PatternDefinitions"] = autorouteSettings.PatternDefinitions; }
public override IEnumerable <TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { if (builder.Name != "AutoroutePart") { yield break; } var settings = new AutorouteSettings { Patterns = new List <RoutePattern>() }; // Get cultures settings.SiteCultures = _cultureManager.ListCultures().ToList(); if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { //TODO need to add validations client and/or server side here // If some default pattern is an empty pattern set it to the first pattern for the language var newDefaultPatterns = new List <DefaultPattern>(); foreach (var defaultPattern in settings.DefaultPatterns) { RoutePattern correspondingPattern = null; if (string.IsNullOrEmpty(defaultPattern.Culture)) { correspondingPattern = settings.Patterns.Where(x => String.IsNullOrEmpty(x.Culture)).ElementAt(Convert.ToInt32(defaultPattern.PatternIndex)); } else { correspondingPattern = settings.Patterns.Where(x => String.Equals(x.Culture, defaultPattern.Culture, StringComparison.OrdinalIgnoreCase)).ElementAt(Convert.ToInt32(defaultPattern.PatternIndex)); } if (String.IsNullOrWhiteSpace(correspondingPattern.Name) && String.IsNullOrWhiteSpace(correspondingPattern.Pattern) && String.IsNullOrWhiteSpace(correspondingPattern.Description)) { newDefaultPatterns.Add(new DefaultPattern { Culture = defaultPattern.Culture, PatternIndex = "0" }); } else { newDefaultPatterns.Add(defaultPattern); } } settings.DefaultPatterns = newDefaultPatterns; // Remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); // Adding a null culture for the culture neutral pattern var cultures = new List <string>(); cultures.Add(null); cultures.AddRange(settings.SiteCultures); //If there is no pattern for some culture create a default one List <RoutePattern> newPatterns = new List <RoutePattern>(); int current = 0; foreach (string culture in cultures) { if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { newPatterns.Add(settings.Patterns[current]); current++; } } else { newPatterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }); _notifier.Warning(T("A default pattern has been added to AutoroutePart")); } } settings.Patterns = newPatterns; // Update the settings builder settings.Build(builder); } yield return(DefinitionTemplate(settings)); }
public override IEnumerable<TemplateViewModel> TypePartEditorUpdate(ContentTypePartDefinitionBuilder builder, IUpdateModel updateModel) { if (builder.Name != "AutoroutePart") yield break; var settings = new AutorouteSettings { Patterns = new List<RoutePattern>() }; //get cultures settings.SiteCultures = _cultureManager.ListCultures().ToList(); if (updateModel.TryUpdateModel(settings, "AutorouteSettings", null, null)) { //TODO need to add validations client and/or server side here // remove empty patterns var patterns = settings.Patterns; patterns.RemoveAll(p => String.IsNullOrWhiteSpace(p.Name) && String.IsNullOrWhiteSpace(p.Pattern) && String.IsNullOrWhiteSpace(p.Description)); //If there is no default pattern for each culture we set default ones List<RoutePattern> newPatterns = new List<RoutePattern>(); int current = 0; foreach (string culture in settings.SiteCultures) { if (settings.Patterns.Any(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { foreach (RoutePattern routePattern in settings.Patterns.Where(x => String.Equals(x.Culture, culture, StringComparison.OrdinalIgnoreCase))) { newPatterns.Add(settings.Patterns[current]); current++; } } else { newPatterns.Add(new RoutePattern { Name = "Title", Description = "my-title", Pattern = "{Content.Slug}", Culture = culture }); _notifier.Warning(T("A default pattern has been added to AutoroutePart")); } } settings.Patterns = newPatterns; // update the settings builder settings.Build(builder); } yield return DefinitionTemplate(settings); }