Using admin theme from within a plugin (v2.0)

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
12 years ago
Hi Skyler,
Here is my constructor code (below) - also when I change the Layout setting in my .cshtml file, it is now throwing the same error in your example.  So my question is what is the correct setting for Layout?

@{
    Layout = "~/Administration/Views/Shared/_AdminLayout.cshtml";
}

Source for SocialMediaController:
using System.Web.Mvc;
using EbpCustom.Plugin.SocialMedia.Models;
using Nop.Services.Configuration;
using Nop.Web.Framework.Controllers;
using Nop.Services.Localization;
using Nop.Admin.Controllers;

namespace EbpCustom.Plugin.SocialMedia.Controllers
{
    public class SocialMediaController : Controller
    {
        private readonly ISettingService _settingService;
        private readonly ILocalizationService _localizationService;
        private readonly SocialLinksSettings _socialMediaLinksSettings;

        public SocialMediaController(ISettingService settingService,
            ILocalizationService localizationService,
            SocialLinksSettings socialMediaLinksSettings)
        {
            this._settingService = settingService;
            this._localizationService = localizationService;
            this._socialMediaLinksSettings = socialMediaLinksSettings;
        }
        
        [AdminAuthorize]
        //[ChildActionOnly]
        public ActionResult Configure()
        {
            var model = new ConfigurationModel();
            model.FacebookLinkURL = _socialMediaLinksSettings.FacebookLinkURL;
            model.TwitterLinkURL = _socialMediaLinksSettings.TwitterLinkURL;
            model.RSSLinkURL = _socialMediaLinksSettings.RSSLinkURL;

            return View("EbpCustom.Plugin.SocialMedia.Views.SocialMedia.Configure", model);
        }

        [HttpPost]
        [AdminAuthorize]
        //[ChildActionOnly]
        public ActionResult Configure(ConfigurationModel model)
        {
            if (!ModelState.IsValid)
                return Configure();
            
            //save settings
            _socialMediaLinksSettings.FacebookLinkURL = model.FacebookLinkURL;
            _socialMediaLinksSettings.TwitterLinkURL = model.TwitterLinkURL;
            _socialMediaLinksSettings.RSSLinkURL = model.RSSLinkURL;
            _settingService.SaveSetting(_socialMediaLinksSettings);
            
            return View("EbpCustom.Plugin.SocialMedia.Views.SocialMedia.Configure", model);
        }

        [ChildActionOnly]
        public ActionResult SiteLinks()
        {
            var model = new SiteLinksModel();
            model.FacebookLinkURL = _socialMediaLinksSettings.FacebookLinkURL;
            model.TwitterLinkURL = _socialMediaLinksSettings.TwitterLinkURL;
            model.RSSLinkURL = _socialMediaLinksSettings.RSSLinkURL;

            return View("EbpCustom.Plugin.SocialMedia.Views.SocialMedia.SiteLinks", model);
        }
    }
}
12 years ago
Scott your layout setup looks fine. That is also what I have in my view.

Did you make the changes required in ThemableRazorViewEngine? You can find those changes in one of my previous posts. Basically it is adding the code below in two places. Review the previous post for this. Once you've completed that we can go on to the next step. :)



//Admin
"~/Administration/Views/{1}/{0}.cshtml",
"~/Administration/Views/{1}/{0}.vbhtml",
"~/Administration/Views/Shared/{0}.cshtml",
"~/Administration/Views/Shared/{0}.vbhtml",
12 years ago
SUCCESS!  
Now, can you help me with installing the localization strings?

Also, is there any way that I can dynamically assign the link when I call the
BuildMenuItem() 
method.  The challege I was having is that its based the
BasePlugin 
class, so there's no access to the Controller and URL helper methods.
12 years ago
ScottMc101 wrote:
SUCCESS!  
Now, can you help me with installing the localization strings?

Also, is there any way that I can dynamically assign the link when I call the
BuildMenuItem() 
method.  The challege I was having is that its based the
BasePlugin 
class, so there's no access to the Controller and URL helper methods.


Read my last post in https://www.nopcommerce.com/boards/t/11315/how-to-extending-nopcommerce-v20.aspx?p=2 this is a very primitive way of installing localization strings.
12 years ago
Thanks Skyler,
You didn't address my other question: Also, is there any way that I can dynamically assign the link when I call the BuildMenuItem()  method.  The challege I was having is that its based the BasePlugin  class, so there's no access to the Controller and URL helper methods.

Any ideas?
12 years ago
ScottMc101 wrote:
Thanks Skyler,
You didn't address my other question: Also, is there any way that I can dynamically assign the link when I call the BuildMenuItem()  method.  The challege I was having is that its based the BasePlugin  class, so there's no access to the Controller and URL helper methods.

Any ideas?


Yeah I forgot about that one. Sorry! I assume you're talking about implementing IAdminMenuPlugin. I'm sure it is possible, but off the top of my head I'm not aware of how to accomplish this. I'll look into it when I have time.
12 years ago
Sure, here you go:

    public class SocialLinksProvider : BasePlugin, IAdminMenuPlugin
    {
        private readonly ILanguageService _languageService;
        private readonly ILocalizationService _localizationService;

        #region CTOR

        public SocialLinksProvider(ILocalizationService localizationService, ILanguageService languageService)
        {
            _localizationService = localizationService;
            _languageService = languageService;
        }
    }
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.