BasePlugin, IWidget and IAdminMenuPlugin in the same plugin

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 лет назад
Hi nopDevelopers

I'm having a problem with admin plugin routing. I already read yesterday's post, and I can't get it to work.

The difference here is that I'm developing a plugin that is both a Widget and a IAdminPlugin. The reason is that I love the new Cms features for the ease of placing widgets in the page, while at the same time the widget is powerful enough to provide a separate admin configuration zone.

The routes for the widget are OK and easy.

The problem is with the IAdminPlugin.BuildMenuItem and how to define the routes added in the RouteProvider class.

Here's my route provider code:


routes.MapRoute("Plugin.Widgets.SlideShow.Configure",
                 "Plugins/SlideShow/Configure/{widgetId}",
                 new { controller = "SlideShow", action = "Configure" },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            );

            routes.MapRoute("Plugin.Widgets.SlideShow.Display",
                 "Plugins/SlideShow/Display/{widgetId}",
                 new { controller = "SlideShow", action = "Display" },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            );

            routes.MapRoute("Plugin.Widgets.SlideShow.Track",
                 "Plugins/SlideShow/Track/{slideId}",
                 new { controller = "SlideShow", action = "Track" },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            );

            //AdminPlugin routes

            routes.MapRoute("Admin.Plugin.Widgets.SlideShow.List",
                 "Admin/Plugins/SlideShow/SlideShow/List",
                 new { controller = "SlideShow", action = "List" },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            ).DataTokens.Add("area", "admin");

            routes.MapRoute("Admin.Plugin.Widgets.SlideShow.TrackingReport",
                 "Admin/Plugins/SlideShow/SlideShow/TrackingReport",
                 new { controller = "SlideShow", action = "TrackingReport" },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            ).DataTokens.Add("area", "admin");


As you can see the first three routes are used for the widget configuration and display. They work OK.

For the last one, I followed the advices I found in the related forum topics of using a 5 part route and adding the "area" DataToken.

Here's is the menu building function:


public void BuildMenuItem(Telerik.Web.Mvc.UI.MenuItemBuilder menuItemBuilder)
        {

            menuItemBuilder.Text("SlideShow").Items(y =>
                {
                    y.Add()
                        .Text("Manage SlideShows")
                        .Url("Admin/Plugins/SlideShow/SlideShow/List");
                    y.Add()
                        .Text("Tracking Report")
                        .Url("Admin/Plugins/SlideShow/SlideShow/TrackingReport");
                });
            
        }


I'm using the Url action and specifying the exact same Url I configured earlier.


When I open the Admin area, I can see the Plugins > SlideShow menu, and the two items 'Manage SlideShows' and 'TrackingReport'. The funny thing is that the Urls are automatically converted into:

http://localhost:3810/Admin/Widget/Admin/Plugins/SlideShow/SlideShow/List


and:

http://localhost:3810/Admin/Widget/Admin/Plugins/SlideShow/SlideShow/TrackingReport


As you can see, the framework is adding a 'Admin/Widget' part to the URL. I've been scanning the source to try to find where and why this is done, but can't find it.

Of course, being 'widget' one the added parts I guess this is related to the Plugin implementing IWidget. Here's the class signatura in case it helps:


public class SlideShowPlugin: BasePlugin, IWidgetPlugin, IAdminMenuPlugin, IConsumer<EntityInserted<Slide>>, IConsumer<EntityUpdated<Slide>>, IConsumer<EntityDeleted<Slide>>


Any hints, ideas or perhaps sample code of a similar project would be appreciated.

Thanks!
12 лет назад
I just seemed to find it out by myself, posting it for reference:

When you implement the IAdminMenuPlugin, the system will automatically add "Admin/Widget" to whatever URL you use in your menu.

So in order to have your registered routes catch this, you must add it in the route registration.

My final code look like this. First, route registration:


routes.MapRoute("Admin.Plugin.Widgets.SlideShow.List",
                 "Admin/Widget/Plugins/SlideShow/List/{widgetId}",
                 new { controller = "SlideShow", action = "List", widgetId = default(int) },
                 new[] { "CallCentrix.Plugin.Widget.SlideShow.Controllers" }
            ).DataTokens.Add("area", "admin");


Notice I'm including the 'Admin/Widget/' that is nevertheless included by the framework.

Then the buildmenu action:


menuItemBuilder.Text("SlideShow").Items(y =>
                {
                    y.Add()
                        .Text("Manage SlideShows")
                        .Url("Plugins/SlideShow/List");
                    y.Add()
                        .Text("Tracking Report")
                        .Url("Plugins/SlideShow/TrackingReport");
                });


Which is the route above without the 'Admin/Widget'. Hope it saves someone else's time! :)

Using the RouteDebugger is more than recommended for this stuff, you can install it using NuGet Package Manager, and enable and disable in web.config (which in turn reloads the app for your plugin debugging pleasure).
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.