public void RegisterAction(string[] widgetZones, string actionName, string controllerName, RouteValueDictionary routeValues, int order = 0) { Guard.NotNull(widgetZones, nameof(widgetZones)); Guard.NotEmpty(actionName, nameof(actionName)); Guard.NotEmpty(controllerName, nameof(controllerName)); if (_zoneWidgetsMap == null) { _zoneWidgetsMap = new Multimap <string, WidgetRouteInfo>(); } var routeInfo = new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues ?? new RouteValueDictionary(), Order = order }; foreach (var zone in widgetZones) { if (zone.HasValue()) { _zoneWidgetsMap.Add(zone, routeInfo); } } }
public void RegisterAction(Regex widgetZoneExpression, string actionName, string controllerName, RouteValueDictionary routeValues, int order = 0) { Guard.NotNull(widgetZoneExpression, nameof(widgetZoneExpression)); Guard.NotEmpty(actionName, nameof(actionName)); Guard.NotEmpty(controllerName, nameof(controllerName)); if (_httpRequest.QueryString["nowidgets"] != null) { return; } if (_zoneExpressionWidgetsMap == null) { _zoneExpressionWidgetsMap = new Multimap <Regex, WidgetRouteInfo>(); } var routeInfo = new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues ?? new RouteValueDictionary(), Order = order }; _zoneExpressionWidgetsMap.Add(widgetZoneExpression, routeInfo); }
public void RegisterAction(string widgetZone, string actionName, string controllerName, RouteValueDictionary routeValues, int order = 0) { Guard.ArgumentNotEmpty(() => widgetZone); Guard.ArgumentNotEmpty(() => actionName); Guard.ArgumentNotEmpty(() => controllerName); var routeInfo = new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues ?? new RouteValueDictionary(), Order = order }; _widgetMap.Add(widgetZone, routeInfo); }
public void RegisterAction(Regex widgetZoneExpression, string actionName, string controllerName, RouteValueDictionary routeValues, int order = 0) { Guard.ArgumentNotNull(() => widgetZoneExpression); Guard.ArgumentNotEmpty(() => actionName); Guard.ArgumentNotEmpty(() => controllerName); if (_zoneExpressionWidgetsMap == null) { _zoneExpressionWidgetsMap = new Multimap <Regex, WidgetRouteInfo>(); } var routeInfo = new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues ?? new RouteValueDictionary(), Order = order }; _zoneExpressionWidgetsMap.Add(widgetZoneExpression, routeInfo); }
public void RegisterAction(Regex widgetZoneExpression, string actionName, string controllerName, RouteValueDictionary routeValues, int order = 0) { Guard.ArgumentNotNull(() => widgetZoneExpression); Guard.ArgumentNotEmpty(() => actionName); Guard.ArgumentNotEmpty(() => controllerName); if (_zoneExpressionWidgetsMap == null) { _zoneExpressionWidgetsMap = new Multimap<Regex, WidgetRouteInfo>(); } var routeInfo = new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues ?? new RouteValueDictionary(), Order = order }; _zoneExpressionWidgetsMap.Add(widgetZoneExpression, routeInfo); }
public virtual IEnumerable<WidgetRouteInfo> GetWidgets(string widgetZone, object model) { string actionName; string controllerName; RouteValueDictionary routeValues; var storeId = _storeContext.CurrentStore.Id; #region Plugin Widgets var widgets = _widgetService.LoadActiveWidgetsByWidgetZone(widgetZone, storeId); foreach (var widget in widgets) { widget.Value.GetDisplayWidgetRoute(widgetZone, model, storeId, out actionName, out controllerName, out routeValues); if (actionName.HasValue() && controllerName.HasValue()) { yield return new WidgetRouteInfo { ActionName = actionName, ControllerName = controllerName, RouteValues = routeValues }; } } #endregion #region Topic Widgets // add special "topic widgets" to the list var allTopicsCacheKey = string.Format(ModelCacheEventConsumer.TOPIC_WIDGET_ALL_MODEL_KEY, storeId, _workContext.WorkingLanguage.Id); // get topic widgets from STATIC cache var topicWidgets = _services.Cache.Get(allTopicsCacheKey, () => { using (var scope = new DbContextScope(forceNoTracking: true)) { var allTopicWidgets = _topicService.GetAllTopics(storeId).Where(x => x.RenderAsWidget).ToList(); var stubs = allTopicWidgets .Select(t => new TopicWidgetStub { Id = t.Id, Bordered = t.WidgetBordered, WrapContent = !t.WidgetWrapContent.HasValue || t.WidgetWrapContent.Value, ShowTitle = t.WidgetShowTitle, SystemName = t.SystemName.SanitizeHtmlId(), Title = t.GetLocalized(x => t.Title), TitleTag = t.TitleTag, Body = t.GetLocalized(x => t.Body), WidgetZones = t.GetWidgetZones().ToArray(), Priority = t.Priority }) .OrderBy(t => t.Priority) .ToList(); return stubs; } }); var byZoneTopicsCacheKey = "SmartStore.TopicWidgets.ZoneMapped"; // save widgets to zones map in request cache var topicsByZone = _cacheManager.Get(byZoneTopicsCacheKey, () => { var map = new Multimap<string, WidgetRouteInfo>(); foreach (var widget in topicWidgets) { var zones = widget.WidgetZones; if (zones != null && zones.Any()) { foreach (var zone in zones.Select(x => x.ToLower())) { var routeInfo = new WidgetRouteInfo { ControllerName = "Topic", ActionName = "TopicWidget", RouteValues = new RouteValueDictionary() { {"Namespaces", "SmartStore.Web.Controllers"}, {"area", null}, {"widgetZone", zone}, {"model", new TopicWidgetModel { Id = widget.Id, SystemName = widget.SystemName, WrapContent = widget.WrapContent, ShowTitle = widget.ShowTitle, IsBordered = widget.Bordered, Title = String.IsNullOrEmpty(widget.Title) ? "div" : widget.Title, TitleTag = widget.TitleTag ?? "h3", Html = widget.Body } } } }; map.Add(zone, routeInfo); } } } return map; #region Obsolete //var result = from t in topicWidgets // where t.WidgetZones.Contains(widgetZone, StringComparer.InvariantCultureIgnoreCase) // orderby t.Priority // select new WidgetRouteInfo // { // ControllerName = "Topic", // ActionName = "TopicWidget", // RouteValues = new RouteValueDictionary() // { // {"Namespaces", "SmartStore.Web.Controllers"}, // {"area", null}, // {"widgetZone", widgetZone}, // {"model", new TopicWidgetModel // { // Id = t.Id, // SystemName = t.SystemName, // ShowTitle = t.ShowTitle, // IsBordered = t.Bordered, // Title = t.Title, // Html = t.Body // } } // } // }; //return result.ToList(); #endregion }); if (topicsByZone.ContainsKey(widgetZone.ToLower())) { var zoneWidgets = topicsByZone[widgetZone.ToLower()]; foreach (var topicWidget in zoneWidgets) { yield return topicWidget; } } #endregion #region Request scoped widgets (provided by IWidgetProvider) var requestScopedWidgets = _widgetProvider.GetWidgets(widgetZone); if (requestScopedWidgets != null) { foreach (var widget in requestScopedWidgets) { yield return widget; } } #endregion }