Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nigel Wilson 915 posts 2002 karma points
    Mar 14, 2019 @ 22:59
    Nigel Wilson
    1

    Umbraco 8 Package Rewrite - Some Help Please

    Hi there

    I thought I'd have a go at rewriting the Tag Manager package (https://our.umbraco.com/packages/backoffice-extensions/tag-manager/) for Umbraco 8.

    I have created project and added UmbracoCMS.Core V8 via Nuget.

    However I am completely lost with respect to getting things referencing as per the screenshot below - PluginController, UmbracoAuthorizedJsonController, ApplicationContext & Sql are all not happy and there are no suggestions with intellisense...

    enter image description here

    Appreciate V8 is a totally new beast and in no way expected everything to just work, so seeking some pointers / initial help to get my moving on this.

    Thanks

    Nigel

  • Nik 1087 posts 4500 karma points MVP 2x c-trib
    Mar 14, 2019 @ 23:19
    Nik
    2

    Hey Nigel,

    Okay, so you will need to install the UmbracoCms.Web package as well I believe.

    The PluginController attribute is in the following namespace Umbraco.Web.Mvc

    The UmbracoAuthorizedJsonController controller is in the following namespace Umbraco.Web.Editors

    As for the database stuff, I believe you need to use the scopeProvider to create a scope that then gives you access to the database. There have been some questions on this recently on the forum but I can't recall where they are sorry.

    Nik

  • Nik 1087 posts 4500 karma points MVP 2x c-trib
    Mar 14, 2019 @ 23:26
  • Nigel Wilson 915 posts 2002 karma points
    Mar 14, 2019 @ 23:36
    Nigel Wilson
    0

    Hey Nik

    Really appreciate the info - thank you.

    Making some progress now., although I may be back... :-)

    Cheers

    Nigel

  • Nigel Wilson 915 posts 2002 karma points
    Mar 16, 2019 @ 07:01
    Nigel Wilson
    0

    OK, next wee issue:

    Previously the ContentService had a SetTags() method...

    This is not available within V8.

    The TagService documentation only details Get methods.

    Is anyone able to advise how to set tags programmatically on content and media in V8 please ?

    Thanks

    Nigel

  • Marc Goodson 945 posts 6284 karma points MVP 4x c-trib
    Mar 16, 2019 @ 07:50
    Marc Goodson
    1

    Hi Nigel

    There is a new extension method called 'AssignTags' on IContentBase that replaces SetTags in V8:

     public static void AssignTags(this IContentBase content, string propertyTypeAlias, IEnumerable<string> tags, bool merge = false, string culture = null)
    

    You can see some examples of it's use in the ContentServiceTags unit tests:

    https://github.com/umbraco/Umbraco-CMS/blob/91c52cffc8b7c70dc956f6c6610460be2d1adc51/src/Umbraco.Tests/Services/ContentServiceTagsTests.cs

    Regards

    Marc

  • Nigel Wilson 915 posts 2002 karma points
    Mar 16, 2019 @ 17:36
    Nigel Wilson
    0

    Hi Marc

    Awesome stuff - thanks for that.

    Down to 6 errors now when building. :-)

    Nigel

  • Nigel Wilson 915 posts 2002 karma points
    Mar 24, 2019 @ 01:10
    Nigel Wilson
    0

    OK, next issue I've got is as follows:

    So currently I have the following controller for my TagManager Tree

    public class TagManagerTreeController : TreeController
    {
        private TagManagerAPIController tmapictlr;
    
        public TagManagerTreeController()
        {            
            tmapictlr = new TagManagerAPIController();
        }
    ...
    }
    

    But tmapictlr = new TagManagerAPIController(); isn't happy as my APIController is as follows:

    [PluginController("TagManager")]
    public class TagManagerAPIController : UmbracoAuthorizedJsonController, IUserComposer
        {
        private IScopeProvider _scopeProvider;
    
        public TagManagerAPIController(IScopeProvider scopeProvider)
        {
           _scopeProvider = scopeProvider;
        }
    ...
    }
    

    Quite simply I don't understand how to create / pass a "scopeProvider" to my constructor method.

    Is anyone able to please help ?

    Thanks

  • Sebastiaan Janssen 4838 posts 14292 karma points MVP admin hq
    Mar 24, 2019 @ 09:56
    Sebastiaan Janssen
    0

    Why do you need to instantiate an apicontroller though? :-) They exist so that an http request can come in and ask for something.

    That said, if you need to instantiate any class then you can opt it into dependency injection as well.

    A bit of background info: https://www.zpqrtbnk.net/posts/composing-umbraco-v8/

    So you could do something like this to register your API controller:

    [RuntimeLevel(MinLevel = RuntimeLevel.Run)]
    public class MyComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Register<TagManagerAPIController>(Lifetime.Singleton);
        }
    }
    

    Then when you need it you ask for it:

    public class TagManagerTreeController : TreeController
    {
        private readonly TagManagerAPIController _tmapictlr;
    
        public TagManagerTreeController(TagManagerAPIController tagManagerAPIController)
        {            
            _tmapictlr = tagManagerAPIController;
        }
    ...
    }
    
  • Nigel Wilson 915 posts 2002 karma points
    Mar 24, 2019 @ 18:24
    Nigel Wilson
    0

    Hi Sebastiaan

    Thanks for the information - I'll take a look.

    I use an API controller as the Tag Manager package "massages" tags at the database level via a custom admin section in Umbraco.

    Is this the best approach ? Or should the server side code be done a different / better way ?

    Cheers

    Nigel

  • Sebastiaan Janssen 4838 posts 14292 karma points MVP admin hq
    Mar 25, 2019 @ 08:02
    Sebastiaan Janssen
    0

    I don't really have the answers, it just feels wrong to call a controller from a controller. Typically I would call a centralized service to do something for me. A service would also work for both controllers and be injectible with DI. Then you'd update the code above to register a TagManagerService (and you would ask for it in both controllers.

  • Nigel Wilson 915 posts 2002 karma points
    Mar 25, 2019 @ 17:16
    Nigel Wilson
    0

    Hi Sebastiaan

    Got where you are coming from now, and what you have described makes sense, just a level above where I am at, especially in terms of DI. I can swim, but I will never be at the Olympics kinda stuff - ;-)

    Cheers again]

    Nigel

Please Sign in or register to post replies

Write your reply to:

Draft