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...
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.
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.
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.
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.
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 - ;-)
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...
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
Hey Nigel,
Okay, so you will need to install the
UmbracoCms.Web
package as well I believe.The
PluginController
attribute is in the following namespaceUmbraco.Web.Mvc
The
UmbracoAuthorizedJsonController
controller is in the following namespaceUmbraco.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
Update...
Accessing the database examples can be found here:
https://our.umbraco.com/forum/umbraco-8/96075-alternative-solution-to-use-applicationcontextcurrentdatabasecontextdatabase-in-umbraco-8
:-)
Hey Nik
Really appreciate the info - thank you.
Making some progress now., although I may be back... :-)
Cheers
Nigel
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
Hi Nigel
There is a new extension method called 'AssignTags' on IContentBase that replaces SetTags in V8:
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
Hi Marc
Awesome stuff - thanks for that.
Down to 6 errors now when building. :-)
Nigel
OK, next issue I've got is as follows:
So currently I have the following controller for my TagManager Tree
But tmapictlr = new TagManagerAPIController(); isn't happy as my APIController is as follows:
Quite simply I don't understand how to create / pass a "scopeProvider" to my constructor method.
Is anyone able to please help ?
Thanks
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:
Then when you need it you ask for it:
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
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.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
is working on a reply...