mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-20 18:57:56 +08:00
Moved slugs management from Blogs and Pages to Routable
Corrected slug generation on client side
This commit is contained in:
@@ -27,14 +27,12 @@ namespace Orchard.Blogs.Drivers {
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly IBlogService _blogService;
|
||||
private readonly IBlogPostService _blogPostService;
|
||||
private readonly IRoutableService _routableService;
|
||||
|
||||
public BlogDriver(IOrchardServices services, IContentManager contentManager, IBlogService blogService, IBlogPostService blogPostService, IRoutableService routableService) {
|
||||
public BlogDriver(IOrchardServices services, IContentManager contentManager, IBlogService blogService, IBlogPostService blogPostService) {
|
||||
Services = services;
|
||||
_contentManager = contentManager;
|
||||
_blogService = blogService;
|
||||
_blogPostService = blogPostService;
|
||||
_routableService = routableService;
|
||||
T = NullLocalizer.Instance;
|
||||
}
|
||||
|
||||
@@ -97,47 +95,9 @@ namespace Orchard.Blogs.Drivers {
|
||||
protected override DriverResult Editor(Blog blog, IUpdateModel updater) {
|
||||
updater.TryUpdateModel(blog, Prefix, null, null);
|
||||
|
||||
//todo: (heskew) something better needs to be done with this...still feels shoehorned in here
|
||||
ProcessSlug(blog, updater);
|
||||
|
||||
return Combined(
|
||||
ContentItemTemplate("Items/Blogs.Blog"),
|
||||
ContentPartTemplate(blog, "Parts/Blogs.Blog.Fields").Location("primary", "1"));
|
||||
}
|
||||
|
||||
private void ProcessSlug(Blog blog, IUpdateModel updater) {
|
||||
_routableService.FillSlug(blog.As<RoutableAspect>());
|
||||
|
||||
|
||||
if (string.IsNullOrEmpty(blog.Slug)) {
|
||||
return;
|
||||
|
||||
// OR
|
||||
|
||||
// updater.AddModelError("Routable.Slug", T("The slug is required.").ToString());
|
||||
// return;
|
||||
}
|
||||
|
||||
|
||||
if (!Regex.IsMatch(blog.Slug, @"^[^/:?#\[\]@!$&'()*+,;=\s]+$")) {
|
||||
//todo: (heskew) get rid of the hard-coded prefix
|
||||
updater.AddModelError("Routable.Slug", T("Please do not use any of the following characters in your slugs: \"/\", \":\", \"?\", \"#\", \"[\", \"]\", \"@\", \"!\", \"$\", \"&\", \"'\", \"(\", \")\", \"*\", \"+\", \",\", \";\", \"=\". No spaces are allowed (please use dashes or underscores instead).").ToString());
|
||||
}
|
||||
|
||||
var slugsLikeThis = _blogService.Get().Where(
|
||||
b => b.Slug.StartsWith(blog.Slug, StringComparison.OrdinalIgnoreCase) &&
|
||||
b.Id != blog.Id).Select(b => b.Slug);
|
||||
|
||||
//todo: (heskew) need better messages
|
||||
if (slugsLikeThis.Count() > 0) {
|
||||
var originalSlug = blog.Slug;
|
||||
//todo: (heskew) make auto-uniqueness optional
|
||||
blog.Slug = _routableService.GenerateUniqueSlug(blog.Slug, slugsLikeThis);
|
||||
|
||||
if (originalSlug != blog.Slug)
|
||||
Services.Notifier.Warning(T("Slugs in conflict. \"{0}\" is already set for a previously created blog so this blog now has the slug \"{1}\"",
|
||||
originalSlug, blog.Slug));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user