public RoutablePathConstraintUpdator(IRoutablePathConstraint pageSlugConstraint, IRepository<RoutePartRecord> repository) {
     _pageSlugConstraint = pageSlugConstraint;
     _repository = repository;
 }
示例#2
0
 public Routes(IRoutablePathConstraint routablePathConstraint) {
     _routablePathConstraint = routablePathConstraint;
 }
示例#3
0
        public RoutePartHandler(
            IOrchardServices services,
            IRepository<RoutePartRecord> repository,
            IRoutablePathConstraint routablePathConstraint,
            IRoutableService routableService,
            IContentManager contentManager,
            IWorkContextAccessor workContextAccessor,
            IEnumerable<IHomePageProvider> homePageProviders) {
            _services = services;
            _routablePathConstraint = routablePathConstraint;
            _routableService = routableService;
            _contentManager = contentManager;
            _workContextAccessor = workContextAccessor;
            _routableHomePageProvider = homePageProviders.SingleOrDefault(p => p.GetProviderName() == RoutableHomePageProvider.Name);
            T = NullLocalizer.Instance;

            Filters.Add(StorageFilter.For(repository));

            Action<RoutePart> processSlug = (
                routable => {
                    if (!_routableService.ProcessSlug(routable))
                        _services.Notifier.Warning(T("Permalinks 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));
                });

            OnGetDisplayShape<RoutePart>(SetModelProperties);
            OnGetEditorShape<RoutePart>(SetModelProperties);
            OnUpdateEditorShape<RoutePart>(SetModelProperties);

            Action<PublishContentContext, RoutePart> handler = (context, route) => {
                FinalizePath(route, context, processSlug);

                if (_routableHomePageProvider == null)
                    return;

                var homePageSetting = _workContextAccessor.GetContext().CurrentSite.HomePage;
                var currentHomePageId = !string.IsNullOrWhiteSpace(homePageSetting)
                                            ? _routableHomePageProvider.GetHomePageId(homePageSetting)
                                            : 0;

                if (route.Id != 0 && (route.Id == currentHomePageId || route.PromoteToHomePage)) {

                    if (currentHomePageId != route.Id) {
                        // reset the path on the current home page
                        var currentHomePage = _contentManager.Get(currentHomePageId);
                        if (currentHomePage != null)
                            FinalizePath(currentHomePage.As<RoutePart>(), context, processSlug);
                        // set the new home page
                        _services.WorkContext.CurrentSite.HomePage = _routableHomePageProvider.GetSettingValue(route.ContentItem.Id);
                    }

                    // readjust the constraints of the current current home page
                    _routablePathConstraint.RemovePath(route.Path);
                    route.Path = "";
                    _routableService.FixContainedPaths(route);
                    _routablePathConstraint.AddPath(route.Path);
                }
            };

            OnPublished<RoutePart>(handler);
            OnUnpublished<RoutePart>(handler);

            OnRemoved<RoutePart>((context, route) => {
                if (!string.IsNullOrWhiteSpace(route.Path))
                    _routablePathConstraint.RemovePath(route.Path);
            });

            OnIndexing<RoutePart>((context, part) => context.DocumentIndex.Add("title", part.Record.Title).RemoveTags().Analyze());
        }