Esempio n. 1
0
        private bool TryConvertContentToController(RequestContext request, RouteValueDictionary values, string key, out ContentItem item)
        {
            if (!values.ContainsKey(key))
            {
                item = null;
                return false;
            }

            object value = values[key];
            item = value as ContentItem;
            if (item == null && value is int)
            {
                item = engine.Persister.Get((int)value);
            }

            if (item == null || item == request.CurrentItem())
                // got item from merged values
                return false;

            // replace requested controller when other "item" is passed
            values.Remove(key);
            values[ControllerKey] = controllerMapper.GetControllerName(item.GetContentType());

            return true;
        }
Esempio n. 2
0
        public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values)
        {
            ContentItem item;

            Debug.WriteLine("GetVirtualPath for values: " + values.ToQueryString());

            values = new RouteValueDictionary(values);

            // try retrieving the item from the route values
            if (!TryConvertContentToController(requestContext, values, ContentItemKey, out item))
            {
                // no item was passed, fallback to current content item
                item = requestContext.CurrentItem();

                if (item == null)
                    // no item = no play
                    return null;

                if (!RequestedControllerMatchesItemController(values, item))
                    // someone's asking for a specific controller so we let another route handle it
                    return null;
            }

            if (item.IsPage)
                return ResolveContentActionUrl(requestContext, values, item);

            // try to find an appropriate page to use as path (part data goes into the query strings)
            ContentItem page = values.CurrentItem<ContentItem>(ContentPageKey, engine.Persister);
            if (page != null)
                // a page parameter was passed
                return ResolvePartActionUrl(requestContext, values, page, item);

            page = requestContext.CurrentPage<ContentItem>();
            if (page != null && page.IsPage)
                // next use the current page
                return ResolvePartActionUrl(requestContext, values, page, item);

            page = item.ClosestPage();
            if (page != null && page.IsPage)
                // fallback to finding the closest page
                return ResolvePartActionUrl(requestContext, values, page, item);

            // can't find a page, don't link
            return null;
        }