2010-01-20 09:26:33 +00:00
|
|
|
|
using System.Text;
|
|
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Orchard.ContentManagement;
|
|
|
|
|
using Orchard.ContentManagement.Aspects;
|
|
|
|
|
using Orchard.ContentManagement.Handlers;
|
2010-03-03 00:40:32 -08:00
|
|
|
|
using Orchard.Core.Common.Records;
|
|
|
|
|
using Orchard.Data;
|
2010-01-20 09:26:33 +00:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Core.Common.Models {
|
|
|
|
|
[UsedImplicitly]
|
2010-03-03 00:40:32 -08:00
|
|
|
|
public class RoutableAspectHandler : ContentHandler {
|
|
|
|
|
public RoutableAspectHandler(IRepository<RoutableRecord> repository) {
|
|
|
|
|
Filters.Add(StorageFilter.For(repository));
|
|
|
|
|
|
2010-01-20 09:26:33 +00:00
|
|
|
|
OnGetEditorViewModel<RoutableAspect>((context, routable) => {
|
|
|
|
|
var containerPathBuilder = new StringBuilder();
|
|
|
|
|
var container = context.ContentItem.As<ICommonAspect>().Container;
|
|
|
|
|
|
|
|
|
|
while (container != null) {
|
|
|
|
|
if (container.Is<RoutableAspect>())
|
|
|
|
|
containerPathBuilder.Insert(0, string.Format("{0}/", container.As<RoutableAspect>().Slug));
|
|
|
|
|
container = container.ContentItem.As<ICommonAspect>().Container;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
routable.ContainerPath = containerPathBuilder.ToString();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|