Updating the Routeable slugify to use the item's path

--HG--
branch : dev
This commit is contained in:
Nathan Heskew
2010-11-13 08:37:13 -08:00
parent 036033116f
commit e56c682586
5 changed files with 7 additions and 25 deletions

View File

@@ -44,21 +44,8 @@ namespace Orchard.Core.Containers.Drivers {
if (updater != null) {
var oldContainerId = model.ContainerId;
updater.TryUpdateModel(model, "Containable", null, null);
if (oldContainerId != model.ContainerId) {
if (oldContainerId != model.ContainerId)
commonPart.Container = _contentManager.Get(model.ContainerId, VersionOptions.Latest);
// reprocess slug
var routable = part.As<IRoutableAspect>();
_routableService.ProcessSlug(part.As<IRoutableAspect>());
if (!_routableService.ProcessSlug(routable)) {
var existingConflict = _services.Notifier.List().FirstOrDefault(n => n.Message.TextHint == "Slugs in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"");
if (existingConflict != null)
existingConflict.Message = T("Slugs in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
routable.Slug, routable.GetEffectiveSlug(), routable.ContentItem.ContentType);
else
_services.Notifier.Warning(T("Slugs in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
routable.Slug, routable.GetEffectiveSlug(), routable.ContentItem.ContentType));
}
}
}
var containers = _contentManager.Query<ContainerPart, ContainerPartRecord>(VersionOptions.Latest).List();

View File

@@ -213,10 +213,7 @@ namespace Orchard.Core.Contents.Controllers {
if (!Services.Authorizer.Authorize(Permissions.PublishContent, contentItem, T("Couldn't create content")))
return new HttpUnauthorizedResult();
var isDraftable = contentItem.TypeDefinition.Settings.GetModel<ContentTypeSettings>().Draftable;
_contentManager.Create(
contentItem,
isDraftable ? VersionOptions.Draft : VersionOptions.Published);
_contentManager.Create(contentItem, VersionOptions.Draft);
var model = _contentManager.UpdateEditor(contentItem, this);
if (!ModelState.IsValid) {

View File

@@ -4,6 +4,7 @@ using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.ContentManagement.Aspects;
using Orchard.Core.Routable.Models;
using Orchard.Core.Routable.Services;
using Orchard.Data;
using Orchard.DisplayManagement;
using Orchard.Localization;
@@ -62,7 +63,7 @@ namespace Orchard.Core.Routable.Controllers {
contentItem = _contentManager.Get((int)id, VersionOptions.Latest);
if (contentItem == null) {
contentItem = _contentManager.New(contentType);
contentItem = _contentManager.Create(contentType, VersionOptions.Draft);
if (containerId != null) {
var containerItem = _contentManager.Get((int)containerId);
@@ -71,9 +72,10 @@ namespace Orchard.Core.Routable.Controllers {
}
_contentManager.UpdateEditor(contentItem, this);
_contentManager.Publish(contentItem);
_transactionManager.Cancel();
return Json(contentItem.As<IRoutableAspect>().Slug ?? slug);
return Json(contentItem.As<IRoutableAspect>().GetEffectiveSlug() ?? slug);
}

View File

@@ -79,10 +79,6 @@ namespace Orchard.Core.Routable.Drivers {
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)."));
}
if (!_routableService.ProcessSlug(part))
_services.Notifier.Warning(T("Slugs in conflict. \"{0}\" is already set for a previously created {2} so now it has the slug \"{1}\"",
part.Slug, part.GetEffectiveSlug(), part.ContentItem.ContentType));
if (part.ContentItem.Id != 0 && model.PromoteToHomePage && _routableHomePageProvider != null)
_services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(part.ContentItem.Id);

View File

@@ -33,7 +33,7 @@ namespace Orchard.Core.Routable.Handlers {
OnGetEditorShape<RoutePart>(SetModelProperties);
OnUpdateEditorShape<RoutePart>(SetModelProperties);
OnPublished<RoutePart>((context, routable) => {
OnPublishing<RoutePart>((context, routable) => {
if (context.PublishingItemVersionRecord != null)
processSlug(routable);
if (!string.IsNullOrEmpty(routable.Path))